#include <bits/stdc++.h>
#define I64 long long

using namespace std;

struct integer {
	static const int P = (int) 1E9 + 7;
	int u;
	explicit operator int () const {
		return u;
	}
	integer() : u(0) {
		
	}
	integer(I64 x) : u((int) (x % P)) {
		if (u < 0) {
			u = u + P;
		}
	}
	integer& operator += (integer a) {
		u = u + a.u;
		if (u >= P) {
			u = u - P;
		}
		return *this;
	}
	integer& operator -= (integer a) {
		u = u - a.u;
		if (u < 0) {
			u = u + P;
		}
		return *this;
	}
	integer& operator *= (integer a) {
		u = (int) ((I64) u * a.u % P);
		return *this;
	}
	friend integer operator + (integer a, integer b) {
		return a += b;
	}
	friend integer operator - (integer a, integer b) {
		return a -= b;
	}
	friend integer operator * (integer a, integer b) {
		return a *= b;
	}
	friend istream& operator >> (istream& i, integer &a) {
		I64 x;
		i >> x;
		a = integer(x);
		return i;
	}
	friend ostream& operator << (ostream& o, integer a) {
		o << (int) a;
		return o;
	}
};

namespace A {
	const int N = (int) 1E5 + 5;
	
	int n, k;
	int d[N];
	integer f[N];
	
	void solve() {
		cin >> n >> k;
		assert(k == 1);
		fill(d, d + n, 0);
		for (int i = 0; i < n - 1; i++) {
			int u, v;
			cin >> u >> v;
			u = u - 1;
			v = v - 1;
			d[u] = d[u] + 1;
			d[v] = d[v] + 1;
		}
		f[0] = 1;
		for (int i = 1; i <= n; i++) {
			f[i] = f[i - 1] * i;
		}
		int x;
		cin >> x;
		x = x - 1;
		integer c = 1;
		for (int u = 0; u < n; u++) {
			c = c * f[d[u] - 1];
		}
		cout << c << "\n";
	}
};

namespace B {
	void solve() {
		cout << 1 << "\n";
	}
};

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int c, t;
	cin >> c >> t;
	if (c >= 1 && c <= 6) {
		for (int i = 0; i < t; i++) {
			A::solve();
		}
	} else if (c == 18) {
		for (int i = 0; i < t; i++) {
			B::solve();
		}
	}
	return 0;
}
