#include <bits/stdc++.h>
using namespace std;
int read() {
    char ch = getchar();
    int x = 0;
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x;
}

int c;

namespace Solve {
    const int M = 1e5 + 10, mod = 1e9 + 7;

    int n, k, x[M], y[M];
    vector<int> g[M];

    namespace Chain {
        void mian() {
            for (int i = 1; i <= k; i++) {
                printf("1\n");
            }
            return ;
        }
    }
    namespace Flower {
        void mian() {
            int ans = 1;
            for (int i = 1; i <= n - 2; i++) ans = 1ll * ans * i % mod;
            for (int i = 1; i <= k; i++) {
                printf("%d\n", ans);
            }
            return ;
        }
    }

    void mian() {
        n = read(), k = read();
        for (int i = 1; i <= n; i++) g[i].clear();
        for (int i = 1, u, v; i < n; i++) {
            g[u].emplace_back(v);
            g[v].emplace_back(u);
        }
        for (int i = 1; i <= k; i++)
            x[i] = read(), y[i] = read();
        if (c == 18) printf("1\n");
        else if (19 <= c && c <= 21) Flower::mian();
        else printf("1\n");
        return ;
    }
}

int main() {
    freopen("traverse.in", "r", stdin);
    freopen("traverse.out", "w", stdout);
    c = read();
    int T = read();
    while (T--) Solve::mian();
    return 0;
}
