#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int qu;
    cin >> qu;
    while(qu--){
        ll n,sum = 0,xo = 0;
        vector<ll> v;
        cin >> n;
        queue<ll> q;
        for(int i = 0; i < n; i ++){
            ll a;
            cin >> a;
            sum += a;
            xo ^= a;
            v.push_back(a);
        }
        ll div = abs(sum - (2*xo));
        if(div & 1){
            xo ^= 1;
            sum ++;
            q.push(1);
            div = abs(sum - 2*xo);
        }
        if(sum == 2*xo){
            cout << 0 << endl;
            continue;
        }

        if(sum < 2*xo ){
            q.push(div/2);
            q.push(div/2);
        }
        else{
            int j = 0;
            while(2*xo != sum && j < 3){
                q.push(div);
                xo ^= div;
                sum += div;
                if(sum < 2*xo){
                    div = abs(sum - 2*xo);
                    q.push(div/2);
                    q.push(div/2);
                    break;
                }
                j++;
            }
        }
        cout << q.size() << endl;
        while(!q.empty()){
            cout << q.front() << ' ';
            q.pop();
        }
        cout << endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
long long dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u,int faa)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        if (u == 4)
        {
            u++;
            u--;
        }
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v, u);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    bool flag = 0;
    if ((x == 4 && y == 10) || (x == 10 && y == 4))
        flag = 1;
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    //if (flag == 1)cout << x << y << "[]\n";
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{
    //freopen ("E.in","r", stdin);
    //freopen ("E.out","w", stdout);
    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(n, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            if (used[u] != i)
            {
                used[u] = i;
                que[u].push_back(i);
            }
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    /*for (int i = 1; i <= n; i++)
        cout << que[i].size();*/
    dfs(n, 0);

    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            if (a[k][i].num == 10)
            {
                i++;
                i--;
            }

            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];
            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].num << ":";
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j <= m[k]; j++)
                dp[(i + 1) & 1][j] = 0;
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (dp[i & 1][j] * (long long)(j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        long long ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << (ans + mod) % mod << endl;

    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
long long dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u,int faa)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        if (u == 4)
        {
            u++;
            u--;
        }
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v, u);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    bool flag = 0;
    if ((x == 4 && y == 10) || (x == 10 && y == 4))
        flag = 1;
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    //if (flag == 1)cout << x << y << "[]\n";
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{

    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(1, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            if (used[u] != i)
            {
                used[u] = i;
                que[u].push_back(i);
            }
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    /*for (int i = 1; i <= n; i++)
        cout << que[i].size();*/
    dfs(1, 0);

    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];
            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].num << ":";
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j <= m[k]; j++)
                dp[(i + 1) & 1][j] = 0;
            for (int j = 1; j <= min(i + 1, m[k]); j++)
            {
                if (j - a[k][i].h + 1 < 0 && dp[i & 1][j] != 0)
                    while (1);
                if (j >= a[k][i].h) dp[(i + 1) & 1][j] = (dp[i & 1][j] * (long long)(j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
                else dp[(i + 1) & 1][j] = dp[i & 1][j - 1];
            }
        }
        long long ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << (ans + mod) % mod << endl;

    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
int dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    return x.h < y.h;
}

int main()
{

    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(1, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            used[u] = i;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            que[u].push_back(i);
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    dfs(1);
    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];

            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            memset(dp[(i + 1) & 1], 0, sizeof(dp[(i + 1) & 1]));
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (1ll * dp[i & 1][j] * (j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        int ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
long long dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u,int faa)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        if (u == 4)
        {
            u++;
            u--;
        }
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v, u);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    bool flag = 0;
    if ((x == 4 && y == 10) || (x == 10 && y == 4))
        flag = 1;
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    //if (flag == 1)cout << x << y << "[]\n";
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{

    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(1, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            if (used[u] != i)
            {
                used[u] = i;
                que[u].push_back(i);
            }
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    /*for (int i = 1; i <= n; i++)
        cout << que[i].size();*/
    dfs(1, 0);

    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];
            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].num << ":";
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        for (int j = 0; j < m[k]; j++)
            dp[0][j] = dp[1][j] = 0;

        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j <= m[k]; j++)
                dp[(i + 1) & 1][j] = 0;
            for (int j = 1; j <= min(i + 1, m[k]); j++)
            {
                if (j >= a[k][i].h) dp[(i + 1) & 1][j] = (dp[i & 1][j] * (long long)(j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
                else dp[(i + 1) & 1][j] = dp[i & 1][j - 1];
            }
        }
        long long ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;

    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
int dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(n, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            used[u] = i;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            que[u].push_back(i);
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    dfs(1);
    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];

            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            memset(dp[(i + 1) & 1], 0, sizeof(dp[(i + 1) & 1]));
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (1ll * dp[i & 1][j] * (j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        int ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
int dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(1, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            used[u] = i;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            que[u].push_back(i);
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    dfs(1);
    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];

            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            memset(dp[(i + 1) & 1], 0, sizeof(dp[(i + 1) & 1]));
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (1ll * dp[i & 1][j] * (j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        int ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
int dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u,int faa)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        if (u == 4)
        {
            u++;
            u--;
        }
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v, u);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    bool flag = 0;
    if ((x == 4 && y == 10) || (x == 10 && y == 4))
        flag = 1;
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    //if (flag == 1)cout << x << y << "[]\n";
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{
    //freopen ("E.in","r", stdin);
    //freopen ("E.out","w", stdout);
    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(n, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            if (used[u] != i)
            {
                used[u] = i;
                que[u].push_back(i);
            }
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    /*for (int i = 1; i <= n; i++)
        cout << que[i].size();*/
    dfs(n, 0);

    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            if (a[k][i].num == 10)
            {
                i++;
                i--;
            }

            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];
            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].num << ":";
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j <= m[k]; j++)
                dp[(i + 1) & 1][j] = 0;
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (1ll * dp[i & 1][j] * (j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        int ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;

    }

}


#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, q;
struct Edge
{
    int num;
    int next;
}edge[2 * N];
int tot, last[N];
int fa[N][20], dep[N];
int K[N], m[N], r[N];
int dp[2][305];
int used[N];

struct Data
{
    int num;
    int h;
};

vector<Data>a[N];
vector<int>que[N];
map<int ,int>hs[N];
set<int>sign[N];
int cnt[N];

void Add(int i, int j)
{
    tot++;
    edge[tot].num = j;
    edge[tot].next = last[i];
    last[i] = tot;
}

void dfs1(int u, int father)
{
    fa[u][0] = father;
    dep[u] = dep[father] + 1;
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == father) continue;
        dfs1(v, u);
    }

}

void dfs(int u,int faa)
{
    int s = que[u].size();
    for (int k = 0; k < s; k++)
    {
        if (u == 4)
        {
            u++;
            u--;
        }
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] ++;
        hs[v][u] = cnt[v];
    }
    for (int k = last[u]; k != 0; k = edge[k].next)
    {
        int v = edge[k].num;
        if (v == fa[u][0]) continue;
        dfs(v, u);
    }
    for (int k = 0; k < s; k++)
    {
        int v = que[u][k];
        if (sign[v].count(u))
            cnt[v] --;
    }
}

int LCA(int x, int y)
{
    bool flag = 0;
    if ((x == 4 && y == 10) || (x == 10 && y == 4))
        flag = 1;
    if (dep[x] > dep[y]) swap(x, y);
    for (int j = 19; j >= 0; j--)
         if (dep[fa[y][j]] >= dep[x])
            y = fa[y][j];
    //if (flag == 1)cout << x << y << "[]\n";
    if (x == y) return x;
    for (int j = 19; j >= 0; j--)
        if (fa[y][j] != fa[x][j])
        {
            x = fa[x][j];
            y = fa[y][j];
        }
    return fa[x][0];
}

bool cmp(Data x, Data y)
{
    if (x.h != y.h) return x.h < y.h;
    else dep[x.num] < dep[x.num];
}

int main()
{
    //freopen ("E.in","r", stdin);
    //freopen ("E.out","w", stdout);
    std::ios::sync_with_stdio(0);
    cin >> n >> q;

    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        Add(u, v);
        Add(v, u);
    }

    dfs1(2, 0);
    for (int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            if (fa[i][j - 1] != 0) fa[i][j] = fa[fa[i][j - 1]][j - 1];
            else fa[i][j] = 0;

    for (int i = 1; i <= q; i++)
    {
        cin >> K[i] >> m[i] >> r[i];
        for (int j = 1; j <= K[i]; j++)
        {
            int u;
            cin >> u;
            sign[i].insert(u);
            a[i].push_back((Data){u, 0});
            if (used[u] != i)
            {
                used[u] = i;
                que[u].push_back(i);
            }
            int lca = LCA(u, r[i]);
            if (used[lca] != i)
            {
                used[lca] = i;
                que[lca].push_back(i);
            }
        }
        if (used[r[i]] != i)
        {
            que[r[i]].push_back(i);
            used[r[i]] = i;
        }
    }
    /*for (int i = 1; i <= n; i++)
        cout << que[i].size();*/
    dfs(2, 0);

    for (int k = 1; k <= q; k++)
    {
        int s = a[k].size();
        for (int i = 0; i < s; i++)
        {
            if (a[k][i].num == 10)
            {
                i++;
                i--;
            }

            int lca = LCA(r[k], a[k][i].num);

            //cout << a[k][i].num << ":\n";
            //cout << "lca = " << lca << endl;
            //cout << hs[k][a[k][i].num] << " " << hs[k][r[k]] << " " << hs[k][lca] << endl;
            a[k][i].h = hs[k][a[k][i].num] + hs[k][r[k]] - 2 * hs[k][lca];
            if (sign[k].count(lca))
                a[k][i].h ++;
            //cout << a[k][i].num << ":";
            //cout << a[k][i].h << endl;
        }
        sort(a[k].begin(), a[k].end(), cmp);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        //cout << a[1][0].h << " " << a[1][1].h << endl;
        for (int i = 0; i < s; i++)
        {
            for (int j = 0; j <= m[k]; j++)
                dp[(i + 1) & 1][j] = 0;
            for (int j = 1; j <= min(i + 1, m[k]); j++)
                dp[(i + 1) & 1][j] = (1ll * dp[i & 1][j] * (j - a[k][i].h + 1) + dp[i & 1][j - 1]) % mod;
        }
        int ans = 0;
        for (int j = 1; j <= m[k]; j++)
            ans = (ans + dp[s & 1][j]) % mod;
        cout << ans << endl;

    }

}


#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#include <cassert>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;
#define pii pair<int, int>
#define mp make_pair

ll read() {
    int f = 1;
    ll res = 0;
    char ch;
    do {
        ch = getchar();
        if (ch == '-') f = -f;
    } while (ch < '0' || ch > '9');
    do {
        res = res * 10 + ch - '0';
        ch = getchar();
    } while (ch >= '0' && ch <= '9');
    return f == 1 ? res : -res;
}

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 100010;
const int mod = 1000000007;
const ll INF = 1e18;
int n,m,q;
int A[N], B[N];
char str[N];
ll dp[2][310];

int head[N], to[N * 2], nxt[N * 2], tot;
void addEdge(int u, int v) {
    tot++;
    nxt[tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}

template <class T>
T mmax(T a, T b) {
    return a < b ? b: a;
}

template <class T>
T mmin(T a, T b) {
    return a < b? a: b;
}

int countOne(int set) {
    int res = 0;
    while (set) {
        res++;
        set &= set - 1;
    }
    return res;
}

bool contain(ll set, int i) {
    return (set & (1LL << i)) > 0;
}

ll myPow(ll a, int p) {
    if (p == 0) return 1;
    ll res = myPow(a, p / 2);
    res *= res;
    res %= mod;
    if (p % 2 == 1) {
        res *= a;
        res %= mod;
    }
    return res;
}

void addMode(int &a, ll b) {
    a = (a+b) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

template <class T>
void mySwap(T &a, T &b) {
    T tmp = a;
    a = b;
    b = tmp;
}

int father[N][20], level[N];
int pre[N], post[N], id;
int h[N], ord[N];

void dfs(int u, int fa) {
    pre[u] = ++id;
    father[u][0] = fa;
    level[u] = level[fa] + 1;
    for (int i = 1; i < 20; i++) if (father[u][i-1]) father[u][i] = father[father[u][i-1]][i-1];
    for (int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if (v != fa) {
            dfs(v, u);
        }
    }
    post[u] = ++id;
}

int lca(int u, int v) {
    if (level[u] < level[v]) mySwap(u, v);
    for (int i = 19; i >= 0; i--) if (father[u][i] && level[father[u][i]] >= level[v]) u = father[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) if (father[u][i] && father[v][i] && father[u][i] != father[v][i]) {
        u = father[u][i];
        v = father[v][i];
    }
    return father[u][0];
}

struct BIT {
    int a[N*2], sz;
    void init(int n) {
        sz = n;
        memset(a, 0, sizeof(a));
    }
    void add(int i, int v) {
        for (; i<=sz; i+=i&-i) a[i] += v;
    }
    int getsum(int i) {
        int res = 0;
        for (; i; i-=i&-i) res += a[i];
        return res;
    }
}bit;

bool cmp(int a, int b) {
    return h[a] < h[b];
}

int main() {

    fast_io();
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    memset(father, 0, sizeof(father));
    memset(level, 0, sizeof(level));

    id = 0;
    dfs(1, 0);

    bit.init(n*2);

    for (int i = 0; i < m; i++) {
        int k, b, r;
        cin >> k >> b >> r;
        set<int> nodes;
        for (int j = 0; j < k; j++) {
            cin >> A[j];
            nodes.insert(A[j]);
        }
        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], 1);
            bit.add(post[A[j]], -1);
        }
        for (int j = 0; j < k; j++) {
            h[j] = bit.getsum(pre[A[j]]);
            ord[j] = j;
        }
        sort(ord, ord+k, cmp);
        for (int j = 0; j <= b; j++) dp[0][j] = 0;
        dp[0][1] = 1;
        int cur = 0;
        for (int j = 1; j < k; j++) {
            int ncur = 1 - cur;
            for (int d = 0; d <= b; d++) dp[ncur][d] = 0;
            int cf = lca(A[ord[j]], r);
            int nh = h[ord[j]] + bit.getsum(pre[r]) - 2 * bit.getsum(pre[cf]) + nodes.count(cf) - 1;
            for (int d = nh+1;d<=b; d++) {
                dp[ncur][d] = dp[cur][d] * (d - nh) + dp[cur][d-1];
                dp[ncur][d] %= mod;
            }
            cur = ncur;
        }
        int res = 0;
        for (int j = 1; j <= b; j++) addMode(res, dp[cur][j]);
        cout << res << '\n';

        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], -1);
            bit.add(post[A[j]], 1);
        }
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#include <cassert>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;
#define pii pair<int, int>
#define mp make_pair

ll read() {
    int f = 1;
    ll res = 0;
    char ch;
    do {
        ch = getchar();
        if (ch == '-') f = -f;
    } while (ch < '0' || ch > '9');
    do {
        res = res * 10 + ch - '0';
        ch = getchar();
    } while (ch >= '0' && ch <= '9');
    return f == 1 ? res : -res;
}

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 100010;
const int mod = 1000000007;
const ll INF = 1e18;
int n,m,q;
int A[N], B[N];
char str[N];
ll dp[2][310];

int head[N], to[N * 4], nxt[N * 4], tot;
void addEdge(int u, int v) {
    tot++;
    nxt[tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}

template <class T>
T mmax(T a, T b) {
    return a < b ? b: a;
}

template <class T>
T mmin(T a, T b) {
    return a < b? a: b;
}

int countOne(int set) {
    int res = 0;
    while (set) {
        res++;
        set &= set - 1;
    }
    return res;
}

bool contain(ll set, int i) {
    return (set & (1LL << i)) > 0;
}

ll myPow(ll a, int p) {
    if (p == 0) return 1;
    ll res = myPow(a, p / 2);
    res *= res;
    res %= mod;
    if (p % 2 == 1) {
        res *= a;
        res %= mod;
    }
    return res;
}

void addMode(int &a, ll b) {
    a = (a+b) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

template <class T>
void mySwap(T &a, T &b) {
    T tmp = a;
    a = b;
    b = tmp;
}

int father[N][20], level[N];
int pre[N], post[N], id;
int h[N], ord[N];

void dfs(int u, int fa) {
    pre[u] = ++id;
    father[u][0] = fa;
    level[u] = level[fa] + 1;
    for (int i = 1; i < 20; i++) if (father[u][i-1]) father[u][i] = father[father[u][i-1]][i-1];
    for (int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if (v != fa) {
            dfs(v, u);
        }
    }
    post[u] = ++id;
}

int lca(int u, int v) {
    if (level[u] < level[v]) mySwap(u, v);
    for (int i = 19; i >= 0; i--) if (father[u][i] && level[father[u][i]] >= level[v]) u = father[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) if (father[u][i] && father[v][i] && father[u][i] != father[v][i]) {
        u = father[u][i];
        v = father[v][i];
    }
    return father[u][0];
}

struct BIT {
    int a[N*2], sz;
    void init(int n) {
        sz = n;
        memset(a, 0, sizeof(a));
    }
    void add(int i, int v) {
        for (; i<=sz; i+=i&-i) a[i] += v;
    }
    int getsum(int i) {
        int res = 0;
        for (; i; i-=i&-i) res += a[i];
        return res;
    }
}bit;

bool cmp(int a, int b) {
    return h[a] < h[b];
}

int main() {

    fast_io();
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    memset(father, 0, sizeof(father));
    memset(level, 0, sizeof(level));

    id = 0;
    dfs(1, 0);

    bit.init(n*2);

    for (int i = 0; i < m; i++) {
        int k, b, r;
        cin >> k >> b >> r;
        set<int> nodes;
        for (int j = 0; j < k; j++) {
            cin >> A[j];
            nodes.insert(A[j]);
        }
        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], 1);
            bit.add(post[A[j]], -1);
        }
        for (int j = 0; j < k; j++) {
            int cf = lca(A[ord[j]], r);
            h[j] = bit.getsum(pre[A[j]]) + bit.getsum(pre[r]) - 2 * bit.getsum(pre[cf]) + nodes.count(cf) - 1;
            ord[j] = j;
        }
        sort(ord, ord+k, cmp);
        for (int j = 0; j <= b; j++) dp[0][j] = 0;
        dp[0][1] = 1;
        int cur = 0;
        for (int j = 1; j < k; j++) {
            int ncur = 1 - cur;
            for (int d = 0; d <= b; d++) dp[ncur][d] = 0;

            int nh = h[ord[j]];
            for (int d = nh+1;d<=b; d++) {
                dp[ncur][d] = dp[cur][d] * (d - nh) + dp[cur][d-1];
                dp[ncur][d] %= mod;
            }
            cur = ncur;
        }
        int res = 0;
        for (int j = 1; j <= b; j++) addMode(res, dp[cur][j]);
        cout << res << '\n';

        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], -1);
            bit.add(post[A[j]], 1);
        }
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#include <cassert>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;
#define pii pair<int, int>
#define mp make_pair

ll read() {
    int f = 1;
    ll res = 0;
    char ch;
    do {
        ch = getchar();
        if (ch == '-') f = -f;
    } while (ch < '0' || ch > '9');
    do {
        res = res * 10 + ch - '0';
        ch = getchar();
    } while (ch >= '0' && ch <= '9');
    return f == 1 ? res : -res;
}

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 100010;
const int mod = 1000000007;
const ll INF = 1e18;
int n,m,q;
int A[N], B[N];
char str[N];
ll dp[2][310];

int head[N], to[N * 4], nxt[N * 4], tot;
void addEdge(int u, int v) {
    tot++;
    nxt[tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}

template <class T>
T mmax(T a, T b) {
    return a < b ? b: a;
}

template <class T>
T mmin(T a, T b) {
    return a < b? a: b;
}

int countOne(int set) {
    int res = 0;
    while (set) {
        res++;
        set &= set - 1;
    }
    return res;
}

bool contain(ll set, int i) {
    return (set & (1LL << i)) > 0;
}

ll myPow(ll a, int p) {
    if (p == 0) return 1;
    ll res = myPow(a, p / 2);
    res *= res;
    res %= mod;
    if (p % 2 == 1) {
        res *= a;
        res %= mod;
    }
    return res;
}

void addMode(int &a, ll b) {
    a = (a+b) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

template <class T>
void mySwap(T &a, T &b) {
    T tmp = a;
    a = b;
    b = tmp;
}

int father[N][20], level[N];
int pre[N], post[N], id;
int h[N], ord[N];

void dfs(int u, int fa) {
    pre[u] = ++id;
    father[u][0] = fa;
    level[u] = level[fa] + 1;
    for (int i = 1; i < 20; i++) if (father[u][i-1]) father[u][i] = father[father[u][i-1]][i-1];
    for (int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if (v != fa) {
            dfs(v, u);
        }
    }
    post[u] = ++id;
}

int lca(int u, int v) {
    if (level[u] < level[v]) mySwap(u, v);
    for (int i = 19; i >= 0; i--) if (father[u][i] && level[father[u][i]] >= level[v]) u = father[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) if (father[u][i] && father[v][i] && father[u][i] != father[v][i]) {
        u = father[u][i];
        v = father[v][i];
    }
    return father[u][0];
}

struct BIT {
    int a[N*2], sz;
    void init(int n) {
        sz = n;
        memset(a, 0, sizeof(a));
    }
    void add(int i, int v) {
        for (; i<=sz; i+=i&-i) a[i] += v;
    }
    int getsum(int i) {
        int res = 0;
        for (; i; i-=i&-i) res += a[i];
        return res;
    }
}bit;

bool cmp(int a, int b) {
    return h[a] < h[b];
}

int main() {

    fast_io();
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    memset(father, 0, sizeof(father));
    memset(level, 0, sizeof(level));

    id = 0;
    dfs(1, 0);

    bit.init(n*2);

    for (int i = 0; i < m; i++) {
        int k, b, r;
        cin >> k >> b >> r;
        set<int> nodes;
        for (int j = 0; j < k; j++) {
            cin >> A[j];
            nodes.insert(A[j]);
        }
        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], 1);
            bit.add(post[A[j]], -1);
        }
        for (int j = 0; j < k; j++) {
            h[j] = bit.getsum(pre[A[j]]);
            ord[j] = j;
        }
        sort(ord, ord+k, cmp);
        for (int j = 0; j <= b; j++) dp[0][j] = 0;
        dp[0][1] = 1;
        int cur = 0;
        for (int j = 1; j < k; j++) {
            int ncur = 1 - cur;
            for (int d = 0; d <= b; d++) dp[ncur][d] = 0;
            int cf = lca(A[ord[j]], r);
            int nh = h[ord[j]] + bit.getsum(pre[r]) - 2 * bit.getsum(pre[cf]) + nodes.count(cf) - 1;
            for (int d = nh+1;d<=b; d++) {
                dp[ncur][d] = dp[cur][d] * (d - nh) + dp[cur][d-1];
                dp[ncur][d] %= mod;
            }
            cur = ncur;
        }
        int res = 0;
        for (int j = 1; j <= b; j++) addMode(res, dp[cur][j]);
        cout << res << '\n';

        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], -1);
            bit.add(post[A[j]], 1);
        }
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#include <cassert>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;
#define pii pair<int, int>
#define mp make_pair

ll read() {
    int f = 1;
    ll res = 0;
    char ch;
    do {
        ch = getchar();
        if (ch == '-') f = -f;
    } while (ch < '0' || ch > '9');
    do {
        res = res * 10 + ch - '0';
        ch = getchar();
    } while (ch >= '0' && ch <= '9');
    return f == 1 ? res : -res;
}

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 100010;
const int mod = 1000000007;
const ll INF = 1e18;
int n,m,q;
int A[N], B[N];
char str[N];
ll dp[2][310];

int head[N], to[N * 4], nxt[N * 4], tot;
void addEdge(int u, int v) {
    tot++;
    nxt[tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}

template <class T>
T mmax(T a, T b) {
    return a < b ? b: a;
}

template <class T>
T mmin(T a, T b) {
    return a < b? a: b;
}

int countOne(int set) {
    int res = 0;
    while (set) {
        res++;
        set &= set - 1;
    }
    return res;
}

bool contain(ll set, int i) {
    return (set & (1LL << i)) > 0;
}

ll myPow(ll a, int p) {
    if (p == 0) return 1;
    ll res = myPow(a, p / 2);
    res *= res;
    res %= mod;
    if (p % 2 == 1) {
        res *= a;
        res %= mod;
    }
    return res;
}

void addMode(int &a, ll b) {
    a = (a+b) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

template <class T>
void mySwap(T &a, T &b) {
    T tmp = a;
    a = b;
    b = tmp;
}

int father[N][20], level[N];
int pre[N], post[N], id;
int h[N], ord[N];

void dfs(int u, int fa) {
    pre[u] = ++id;
    father[u][0] = fa;
    level[u] = level[fa] + 1;
    for (int i = 1; i < 20; i++) if (father[u][i-1]) father[u][i] = father[father[u][i-1]][i-1];
    for (int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if (v != fa) {
            dfs(v, u);
        }
    }
    post[u] = ++id;
}

int lca(int u, int v) {
    if (level[u] < level[v]) mySwap(u, v);
    for (int i = 19; i >= 0; i--) if (father[u][i] && level[father[u][i]] >= level[v]) u = father[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) if (father[u][i] && father[v][i] && father[u][i] != father[v][i]) {
        u = father[u][i];
        v = father[v][i];
    }
    return father[u][0];
}

struct BIT {
    int a[N*2], sz;
    void init(int n) {
        sz = n;
        memset(a, 0, sizeof(a));
    }
    void add(int i, int v) {
        for (; i<=sz; i+=i&-i) a[i] += v;
    }
    int getsum(int i) {
        int res = 0;
        for (; i; i-=i&-i) res += a[i];
        return res;
    }
}bit;

bool cmp(int a, int b) {
    return h[a] < h[b];
}

int main() {

    fast_io();
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    memset(father, 0, sizeof(father));
    memset(level, 0, sizeof(level));

    id = 0;
    dfs(1, 0);

    bit.init(n*2);

    for (int i = 0; i < m; i++) {
        int k, b, r;
        cin >> k >> b >> r;
        set<int> nodes;
        for (int j = 0; j < k; j++) {
            cin >> A[j];
            nodes.insert(A[j]);
        }
        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], 1);
            bit.add(post[A[j]], -1);
        }
        for (int j = 0; j < k; j++) {
            int cf = lca(A[j], r);
            h[j] = bit.getsum(pre[A[j]]) + bit.getsum(pre[r]) - 2 * bit.getsum(pre[cf]) + nodes.count(cf) - 1;
            ord[j] = j;
        }
        sort(ord, ord+k, cmp);
        for (int j = 0; j <= b; j++) dp[0][j] = 0;
        dp[0][1] = 1;
        int cur = 0;
        for (int j = 1; j < k; j++) {
            int ncur = 1 - cur;
            for (int d = 0; d <= b; d++) dp[ncur][d] = 0;

            int nh = h[ord[j]];
            for (int d = nh+1;d<=b; d++) {
                dp[ncur][d] = dp[cur][d] * (d - nh) + dp[cur][d-1];
                dp[ncur][d] %= mod;
            }
            cur = ncur;
        }
        int res = 0;
        for (int j = 1; j <= b; j++) addMode(res, dp[cur][j]);
        cout << res << '\n';

        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], -1);
            bit.add(post[A[j]], 1);
        }
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <algorithm>
#include <functional>
#include <map>
#include <cassert>
#include <bitset>
#include <iomanip>

using namespace std;

typedef long long ll;
#define pii pair<int, int>
#define mp make_pair

ll read() {
    int f = 1;
    ll res = 0;
    char ch;
    do {
        ch = getchar();
        if (ch == '-') f = -f;
    } while (ch < '0' || ch > '9');
    do {
        res = res * 10 + ch - '0';
        ch = getchar();
    } while (ch >= '0' && ch <= '9');
    return f == 1 ? res : -res;
}

void fast_io() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 100010;
const int mod = 1000000007;
const ll INF = 1e18;
int n,m,q;
int A[N], B[N];
char str[N];
ll dp[2][310];

int head[N], to[N * 2], nxt[N * 2], tot;
void addEdge(int u, int v) {
    tot++;
    nxt[tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}

template <class T>
T mmax(T a, T b) {
    return a < b ? b: a;
}

template <class T>
T mmin(T a, T b) {
    return a < b? a: b;
}

int countOne(int set) {
    int res = 0;
    while (set) {
        res++;
        set &= set - 1;
    }
    return res;
}

bool contain(ll set, int i) {
    return (set & (1LL << i)) > 0;
}

ll myPow(ll a, int p) {
    if (p == 0) return 1;
    ll res = myPow(a, p / 2);
    res *= res;
    res %= mod;
    if (p % 2 == 1) {
        res *= a;
        res %= mod;
    }
    return res;
}

void addMode(int &a, ll b) {
    a = (a+b) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

template <class T>
void mySwap(T &a, T &b) {
    T tmp = a;
    a = b;
    b = tmp;
}

int father[N][20], level[N];
int pre[N], post[N], id;
int h[N], ord[N];

void dfs(int u, int fa) {
    pre[u] = ++id;
    father[u][0] = fa;
    level[u] = level[fa] + 1;
    for (int i = 1; i < 20; i++) if (father[u][i-1]) father[u][i] = father[father[u][i-1]][i-1];
    for (int i = head[u]; i; i = nxt[i]) {
        int v = to[i];
        if (v != fa) {
            dfs(v, u);
        }
    }
    post[u] = ++id;
}

int lca(int u, int v) {
    if (level[u] < level[v]) mySwap(u, v);
    for (int i = 19; i >= 0; i--) if (father[u][i] && level[father[u][i]] >= level[v]) u = father[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--) if (father[u][i] && father[v][i] && father[u][i] != father[v][i]) {
        u = father[u][i];
        v = father[v][i];
    }
    return father[u][0];
}

struct BIT {
    int a[N*2], sz;
    void init(int n) {
        sz = n;
        memset(a, 0, sizeof(a));
    }
    void add(int i, int v) {
        for (; i<=sz; i+=i&-i) a[i] += v;
    }
    int getsum(int i) {
        int res = 0;
        for (; i; i-=i&-i) res += a[i];
        return res;
    }
}bit;

bool cmp(int a, int b) {
    return h[a] < h[b];
}

int main() {

    fast_io();
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }

    memset(father, 0, sizeof(father));
    memset(level, 0, sizeof(level));

    id = 0;
    dfs(1, 0);

    bit.init(n*2);

    for (int i = 0; i < m; i++) {
        int k, b, r;
        cin >> k >> b >> r;
        set<int> nodes;
        for (int j = 0; j < k; j++) {
            cin >> A[j];
            nodes.insert(A[j]);
        }
        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], 1);
            bit.add(post[A[j]], -1);
        }
        for (int j = 0; j < k; j++) {
            int cf = lca(A[j], r);
            h[j] = bit.getsum(pre[A[j]]) + bit.getsum(pre[r]) - 2 * bit.getsum(pre[cf]) + nodes.count(cf) - 1;
            ord[j] = j;
        }
        sort(ord, ord+k, cmp);
        for (int j = 0; j <= b; j++) dp[0][j] = 0;
        dp[0][1] = 1;
        int cur = 0;
        for (int j = 1; j < k; j++) {
            int ncur = 1 - cur;
            for (int d = 0; d <= b; d++) dp[ncur][d] = 0;

            int nh = h[ord[j]];
            for (int d = nh+1;d<=b; d++) {
                dp[ncur][d] = dp[cur][d] * (d - nh) + dp[cur][d-1];
                dp[ncur][d] %= mod;
            }
            cur = ncur;
        }
        int res = 0;
        for (int j = 1; j <= b; j++) addMode(res, dp[cur][j]);
        cout << res << '\n';

        for (int j = 0; j < k; j++) {
            bit.add(pre[A[j]], -1);
            bit.add(post[A[j]], 1);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

const int MAX_N = 1e5 + 5;
const int MAX_M = 3e2 + 5;
const int MAX_L = 20;
const int MOD = 1e9 + 7;

struct path
{
	int size, ind;
	path *par;
	int *bit;
	path(int size, int ind, path *par): size(size), ind(ind), par(par)
	{
		bit = new int[size + 1];
		memset(bit, 0x00, sizeof(int) * (size + 1));
	}
	void update(int p, int v)
	{
		while (p <= size)
		{
			bit[p] += v;
			p += p & -p;
		}
	}
	int query(int p)
	{
		int res = 0;
		while (p)
		{
			res += bit[p];
			p -= p & -p;
		}
		return res + (par == nullptr ? 0 : par->query(ind));
	}
} *ptr[MAX_N];

int n, q, dpt[MAX_N], hgt[MAX_N], par[MAX_N][MAX_L], dis[MAX_N], ind[MAX_N];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

int probe(int x, int p)
{
	hgt[x] = hgt[p] + 1;
	par[x][0] = p;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int y : adj[x])
		if (y != p)
			dpt[x] = std::max(dpt[x], probe(y, x) + 1);
	return ++dpt[x];
}

void init(int x, path *cur)
{
	bool flag = false;
	ptr[x] = cur;
	for (int y : adj[x])
		if (flag && dpt[y] == dpt[x] - 1)
		{
			flag = true;
			init(y, cur);
		}
		else if (dpt[y] <= dpt[x])
			init(y, new path(dpt[y], cur->size - dpt[x] + 1, cur));
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	probe(1, 0);
	init(1, new path(dpt[1], 0, nullptr));
	while (q--)
	{
		int k, m, r; scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(r, ind[i])] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(r, x);
			int c = ptr[x]->query(ptr[x]->size - dpt[x] + 1)
			      + ptr[r]->query(ptr[r]->size - dpt[r] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 0);
			//printf("%d[%d]-> %d\n", x, v, c);
			for (int j = c + 1; j <= std::min(i + 1, m); ++j)
			{
				(nxt[j] += cur[j] * (j - c) + cur[j - 1]) %= MOD;
				//printf("f %d = %lld\n", j, nxt[j]);
			}
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * std::min(i + 2, m + 1));
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, 1);
		}
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i];
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

const int MAX_N = 1e5 + 5;
const int MAX_M = 3e2 + 5;
const int MAX_L = 20;
const int MOD = 1e9 + 7;

struct path
{
	int size, ind;
	path *par;
	int *bit;
	path(int size, int ind, path *par): size(size), ind(ind), par(par)
	{
		bit = new int[size + 1];
		memset(bit, 0x00, sizeof(int) * (size + 1));
	}
	void update(int p, int v)
	{
		while (p <= size)
		{
			bit[p] += v;
			p += p & -p;
		}
	}
	int query(int p)
	{
		int res = 0;
		while (p)
		{
			res += bit[p];
			p -= p & -p;
		}
		return res + (par == nullptr ? 0 : par->query(ind));
	}
} *ptr[MAX_N];

int n, q, dpt[MAX_N], hgt[MAX_N], par[MAX_N][MAX_L], dis[MAX_N], ind[MAX_N];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

int probe(int x, int p)
{
	hgt[x] = hgt[p] + 1;
	par[x][0] = p;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int y : adj[x])
		if (y != p)
			dpt[x] = std::max(dpt[x], probe(y, x) + 1);
	return ++dpt[x];
}

void init(int x, path *cur)
{
	bool flag = false;
	ptr[x] = cur;
	for (int y : adj[x])
		if (flag && dpt[y] == dpt[x] - 1)
		{
			flag = true;
			init(y, cur);
		}
		else if (dpt[y] <= dpt[x])
			init(y, new path(dpt[y], cur->size - dpt[x] + 1, cur));
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	probe(1, 0);
	init(1, new path(dpt[1], 0, nullptr));
	while (q--)
	{
		int k, m, r; scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(r, ind[i])] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(r, x);
			int c = ptr[x]->query(ptr[x]->size - dpt[x] + 1)
			      + ptr[r]->query(ptr[r]->size - dpt[r] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 0);
			//printf("%d[%d]-> %d\n", x, v, c);
			for (int j = c + 1; j <= i + 1; ++j)
			{
				(nxt[j] += cur[j] * (j - c) + cur[j - 1]) %= MOD;
				//printf("f %d = %lld\n", j, nxt[j]);
			}
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * (i + 2));
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, 1);
		}
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i];
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

const int MAX_N = 1e5 + 5;
const int MAX_M = 3e2 + 5;
const int MAX_L = 20;
const int MOD = 1e9 + 7;

struct path
{
	int size, ind;
	path *par;
	int *bit;
	path(int size, int ind, path *par): size(size), ind(ind), par(par)
	{
		bit = new int[size + 1];
		memset(bit, 0x00, sizeof(int) * (size + 1));
	}
	void update(int p, int v)
	{
		while (p <= size)
		{
			bit[p] += v;
			p += p & -p;
		}
	}
	int query(int p)
	{
		int res = 0;
		while (p)
		{
			res += bit[p];
			p -= p & -p;
		}
		return res + (par == nullptr ? 0 : par->query(ind));
	}
} *ptr[MAX_N];

int n, q, dpt[MAX_N], hgt[MAX_N], par[MAX_N][MAX_L], dis[MAX_N], ind[MAX_N];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

int probe(int x, int p)
{
	hgt[x] = hgt[p] + 1;
	par[x][0] = p;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int y : adj[x])
		if (y != p)
			dpt[x] = std::max(dpt[x], probe(y, x) + 1);
	return ++dpt[x];
}

void init(int x, path *cur)
{
	bool flag = false;
	ptr[x] = cur;
	for (int y : adj[x])
		if (flag && dpt[y] == dpt[x] - 1)
		{
			flag = true;
			init(y, cur);
		}
		else if (dpt[y] <= dpt[x])
			init(y, new path(dpt[y], cur->size - dpt[x] + 1, cur));
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	probe(1, 0);
	init(1, new path(dpt[1], 0, nullptr));
	while (q--)
	{
		int k, m, r; scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(r, ind[i])] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(r, x);
			int c = ptr[x]->query(ptr[x]->size - dpt[x] + 1)
			      + ptr[r]->query(ptr[r]->size - dpt[r] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 0);
			//printf("%d[%d]-> %d\n", x, v, c);
			for (int j = c + 1; j <= std::min(i + 1, m); ++j)
			{
				(nxt[j] += cur[j] * (j - c) + cur[j - 1]) %= MOD;
				//printf("f %d = %lld\n", j, nxt[j]);
			}
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * (i + 2));
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, 1);
		}
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i];
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

const int MAX_N = 1e5 + 5;
const int MAX_L = 20;
const int MAX_M = 3e2 + 5;
const int MOD = 1e9 + 7;

int n, q, k, m, r, id, hgt[MAX_N], par[MAX_N][MAX_L],
    ind[MAX_N], dis[MAX_N],
    pre[MAX_N], pst[MAX_N], bit[MAX_N * 2];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

void init(int x, int p)
{
	hgt[x] = hgt[par[x][0] = p] + 1;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	pre[x] = ++id;
	for (int y : adj[x])
		if (y != p) init(y, x);
	pst[x] = ++id;
}

void update(int p, int v)
{
	while (p <= id)
	{
		bit[p] += v;
		p += p & -p;
	}
}

int query(int p)
{
	int res = 0;
	while (p)
	{
		res += bit[p];
		p -= p & -p;
	}
	return res;
}

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	init(1, 0);
	while (q--)
	{
		scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(ind[i], r)] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(x, r),
			    c = query(pre[x]) + query(pre[r]) - query(pre[v]) - query(pre[v] - 1);
			for (int j = c + 1; j <= m; ++j)
				nxt[j] = (cur[j - 1] + cur[j] * (j - c)) % MOD;
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * (m + 1));
			update(pre[x], 1); update(pst[x], -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
		for (int i = 0; i < k; ++i)
		{
			update(pre[ind[i]], -1);
			update(pst[ind[i]], 1);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

const int MAX_N = 1e5 + 5;
const int MAX_M = 3e2 + 5;
const int MAX_L = 20;
const int MOD = 1e9 + 7;

struct path
{
	int size, ind;
	path *par;
	int *bit;
	path(int size, int ind, path *par): size(size), ind(ind), par(par)
	{
		bit = new int[size + 1];
		memset(bit, 0x00, sizeof(int) * (size + 1));
	}
	void update(int p, int v)
	{
		while (p <= size)
		{
			bit[p] += v;
			p += p & -p;
		}
	}
	int query(int p)
	{
		int res = 0;
		while (p)
		{
			res += bit[p];
			p -= p & -p;
		}
		return res + (par == nullptr ? 0 : par->query(ind));
	}
} *ptr[MAX_N];

int n, q, dpt[MAX_N], hgt[MAX_N], par[MAX_N][MAX_L], dis[MAX_N], ind[MAX_N];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

int probe(int x, int p)
{
	hgt[x] = hgt[p] + 1;
	par[x][0] = p;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int y : adj[x])
		if (y != p)
			dpt[x] = std::max(dpt[x], probe(y, x) + 1);
	return ++dpt[x];
}

void init(int x, path *cur)
{
	bool flag = false;
	ptr[x] = cur;
	for (int y : adj[x])
		if (flag && dpt[y] == dpt[x] - 1)
		{
			flag = true;
			init(y, cur);
		}
		else if (dpt[y] <= dpt[x])
			init(y, new path(dpt[y], cur->size - dpt[x] + 1, cur));
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	probe(1, 0);
	init(1, new path(dpt[1], 0, nullptr));
	while (q--)
	{
		int k, m, r; scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(r, ind[i])] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(r, x);
			int c = ptr[x]->query(ptr[x]->size - dpt[x] + 1)
			      + ptr[r]->query(ptr[r]->size - dpt[r] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 1)
			      - ptr[v]->query(ptr[v]->size - dpt[v] + 0);
			//printf("%d[%d]-> %d\n", x, v, c);
			for (int j = c + 1; j <= m; ++j)
			{
				(nxt[j] += cur[j] * (j - c) + cur[j - 1]) %= MOD;
				//printf("f %d = %lld\n", j, nxt[j]);
			}
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * (m + 1));
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, 1);
		}
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i];
			ptr[x]->update(ptr[x]->size - dpt[x] + 1, -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

// what the fuck is a denial of judgement ...

const int MAX_N = 1e5 + 5;
const int MAX_L = 20;
const int MAX_M = 3e2 + 5;
const int MOD = 1e9 + 7;

int n, q, k, m, r, id, hgt[MAX_N], par[MAX_N][MAX_L],
    ind[MAX_N], dis[MAX_N],
    pre[MAX_N], pst[MAX_N], bit[MAX_N * 2];
long long cur[MAX_M], nxt[MAX_M];
std::vector<int> adj[MAX_N];

void init(int x, int p)
{
	hgt[x] = hgt[par[x][0] = p] + 1;
	for (int i = 1; i < MAX_L; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	pre[x] = ++id;
	for (int y : adj[x])
		if (y != p) init(y, x);
	pst[x] = ++id;
}

void update(int p, int v)
{
	while (p <= id)
	{
		bit[p] += v;
		p += p & -p;
	}
}

int query(int p)
{
	int res = 0;
	while (p)
	{
		res += bit[p];
		p -= p & -p;
	}
	return res;
}

int lca(int x, int y)
{
	if (hgt[x] < hgt[y]) std::swap(x, y);
	for (int i = MAX_L - 1; i >= 0; --i)
		if (hgt[x] - (1 << i) >= hgt[y]) x = par[x][i];
	if (x == y) return x;
	for (int i = MAX_L - 1; i >= 0; --i)
		if (par[x][i] != par[y][i])
		{
			x = par[x][i];
			y = par[y][i];
		}
	return par[x][0];
}

bool comp(int x, int y) { return dis[x] < dis[y]; }

int main()
{
	scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	init(1, 0);
	while (q--)
	{
		scanf("%d%d%d", &k, &m, &r);
		for (int i = 0; i < k; ++i)
		{
			scanf("%d", &ind[i]);
			dis[ind[i]] = hgt[ind[i]] + hgt[r] - hgt[lca(ind[i], r)] * 2;
		}
		std::sort(ind, ind + k, comp);
		memset(cur, 0x00, sizeof(long long) * (m + 1));
		memset(nxt, 0x00, sizeof(long long) * (m + 1));
		cur[0] = 1;
		for (int i = 0; i < k; ++i)
		{
			int x = ind[i], v = lca(x, r),
			    c = query(pre[x]) + query(pre[r]) - query(pre[v]) - query(pre[v] - 1);
			for (int j = c + 1; j <= m; ++j)
				nxt[j] = (cur[j - 1] + cur[j] * (j - c)) % MOD;
			std::swap(cur, nxt);
			memset(nxt, 0x00, sizeof(long long) * (m + 1));
			update(pre[x], 1); update(pst[x], -1);
		}
		long long ans = 0;
		for (int i = 0; i <= m; ++i)
			ans += cur[i];
		printf("%lld\n", ans % MOD);
		for (int i = 0; i < k; ++i)
		{
			update(pre[ind[i]], -1);
			update(pst[ind[i]], 1);
		}
	}
	return 0;
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

struct Edge{
	int a,b,next;
	Edge(){}
	Edge(int a, int b, int next):a(a),b(b),next(next){}
}e[1000010];

int p[100010];
int tot;

void add(int a, int b) {
	e[tot] = Edge(a,b,p[a]);
	p[a]=tot++;
}

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],rmq[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[2][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
		path[id++] = t;
	}
}

void init() {
	for(int i = 0; i <id; ++i) {
		rmq[i][0] = path[i];
		//printf("i = %d path = %d\n",i,path[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 0; i < id; ++i) {
			rmq[i][j] = dep[rmq[i][j-1]]<dep[rmq[i+(1<<(j-1))][j-1]]?rmq[i][j-1]:rmq[i+(1<<(j-1))][j-1];
		}
	}
}

int lca(int a, int b) {
	if(in[a]>in[b]) swap(a,b);
	int s = in[a], e = in[b];
	int k = 0;
	for(; (1<<k)<=(e-s+1);++k);
	k--;
	//printf("a = %d b = %d s = %d e = %d k = %d\n",a,b,s,e,k);
	return dep[rmq[s][k]]<dep[rmq[e-(1<<k)+1][k]]?rmq[s][k]:rmq[e-(1<<k)+1][k];
}

int k,m,r;
int v[100010];
int num;
vector<int> nima;

void dfs1(int t, int fa) {
	//printf("dfs1 t = %d fa = %d num = %d %d\n",t,fa,num,v[t]);
	f[t] = num;
	if(v[t]){
		nima.pb(t);
		++num;
	}
	for(int i = p[t]; i !=-1; i = e[i].next) {
		if(e[i].b==fa)continue;
		dfs1(e[i].b,t);
	}

	if(v[t])--num;
}
int sol() {

//	clr(v);
	auto cmp = [&](const int i, int j) {
		return in[i]<in[j];
	};

	for(int i = 0; i < k; ++i) {
		v[a[i]]=1;
	}
	if(v[r]==0) {
		a[k++]=r;
	}

	sort(a,a+k,cmp);

	int flag = 0;
	set<int> sb;
	vector<int> ft;
	for(int i = 0; i < k; ++i) {
		if(i==0) {
			ft.pb(a[i]);
			sb.insert(a[i]);
		}
		else {
			int lca_i = lca(a[i],a[i-1]);
			//printf("lca i = %d i-1 = %d lca = %d\n",a[i],a[i-1],lca_i);
			if(sb.find(lca_i)==sb.end()) {
				sb.insert(lca_i);
				ft.pb(lca_i);
			}
			sb.insert(a[i]);
			ft.pb(a[i]);
		}
	}

	sort(ft.begin(), ft.end(),cmp);
	stack<int> st;

	_clr(p);
	tot = 0;
	for(int i = 0; i < ft.size();++i) {
		//printf("ft i = %d ft = %d\n",i,ft[i]);
		while(!st.empty()&&lca(ft[i],st.top())!=st.top()) st.pop();
		if(st.size()){
			//printf("add %d %d\n",ft[i],st.top());
			add(ft[i],st.top());
			add(st.top(),ft[i]);
		}
		st.push(ft[i]);
	}
	num = 0;
	nima.clear();
	dfs1(r,r);

	clr(dp);
	dp[1][1] = 1;
	//printf("i = 0 a = %d\n",nima[0]);
	for(int i = 2; i <= nima.size(); ++i) {
		int index = i&1;
		int pre = index ^1;
		clr(dp[index]);
		for(int j = 1; j <=m; ++j) {
			dp[index][j] = (dp[pre][j-1] + dp[pre][j]*(j-f[nima[i-1]]))%mod;
			//printf("i = %d j = %d a = %d dp = %lld f = %d\n",i,j,nima[i-1],dp[index][j], f[nima[i-1]]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[(nima.size())&1][i])%mod;
	}
	for(int i = 0; i < nima.size();++i) {
	    v[nima[i]]=0;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

struct Edge{
	int a,b,next;
	Edge(){}
	Edge(int a, int b, int next):a(a),b(b),next(next){}
}e[1000010];

int p[100010];
int tot;

void add(int a, int b) {
	e[tot] = Edge(a,b,p[a]);
	p[a]=tot++;
}

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],rmq[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[2][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
		path[id++] = t;
	}
}

void init() {
	for(int i = 0; i <id; ++i) {
		rmq[i][0] = path[i];
		//printf("i = %d path = %d\n",i,path[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 0; i < id; ++i) {
			rmq[i][j] = dep[rmq[i][j-1]]<dep[rmq[i+(1<<(j-1))][j-1]]?rmq[i][j-1]:rmq[i+(1<<(j-1))][j-1];
		}
	}
}

int lca(int a, int b) {
	if(in[a]>in[b]) swap(a,b);
	int s = in[a], e = in[b];
	int k = 0;
	for(; (1<<k)<=(e-s+1);++k);
	k--;
	//printf("a = %d b = %d s = %d e = %d k = %d\n",a,b,s,e,k);
	return dep[rmq[s][k]]<dep[rmq[e-(1<<k)+1][k]]?rmq[s][k]:rmq[e-(1<<k)+1][k];
}

int k,m,r;
int v[100010];
int num;
vector<int> nima;

void dfs1(int t, int fa) {
	//printf("dfs1 t = %d fa = %d num = %d %d\n",t,fa,num,v[t]);
	f[t] = num;
	if(v[t]){
		nima.pb(t);
		++num;
	}
	for(int i = p[t]; i !=-1; i = e[i].next) {
		if(e[i].b==fa)continue;
		dfs1(e[i].b,t);
	}

	if(v[t])--num;
}
int sol() {

	clr(v);
	auto cmp = [&](const int i, int j) {
		return in[i]<in[j];
	};

	for(int i = 0; i < k; ++i) {
		v[a[i]]=1;
	}
	if(v[r]==0) {
		a[k++]=r;
	}

	sort(a,a+k,cmp);

	int flag = 0;
	set<int> sb;
	vector<int> ft;
	for(int i = 0; i < k; ++i) {
		if(i==0) {
			ft.pb(a[i]);
			//sb.insert(a[i]);
		}
		else {
			int lca_i = lca(a[i],a[i-1]);
			//printf("lca i = %d i-1 = %d lca = %d\n",a[i],a[i-1],lca_i);
			//if(sb.find(lca_i)==sb.end()) {
			//	sb.insert(lca_i);
			if(lca_i!=ft[ft.size()-1])
				ft.pb(lca_i);
			//}
			//sb.insert(a[i]);
			if(a[i]!=ft[ft.size()-1])
				ft.pb(a[i]);
		}
	}

	sort(ft.begin(), ft.end(),cmp);
	stack<int> st;

	_clr(p);
	tot = 0;
	for(int i = 0; i < ft.size();++i) {
		if(i&&ft[i]==ft[i-1])continue;
		//printf("ft i = %d ft = %d\n",i,ft[i]);
		while(!st.empty()&&lca(ft[i],st.top())!=st.top()) st.pop();
		if(st.size()){
		//	printf("add %d %d\n",ft[i],st.top());
			add(ft[i],st.top());
			add(st.top(),ft[i]);
		}
		st.push(ft[i]);
	}
	num = 0;
	nima.clear();
	dfs1(r,r);

	clr(dp);
	dp[1][1] = 1;
	//printf("i = 0 a = %d\n",nima[0]);
	for(int i = 2; i <= nima.size(); ++i) {
		int index = i&1;
		int pre = index ^1;
		clr(dp[index]);
		for(int j = 1; j <=m; ++j) {
			dp[index][j] = (dp[pre][j-1] + dp[pre][j]*(j-f[nima[i-1]]))%mod;
			//printf("i = %d j = %d a = %d dp = %lld f = %d\n",i,j,nima[i-1],dp[index][j], f[nima[i-1]]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[(nima.size())&1][i])%mod;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

struct Edge{
	int a,b,next;
	Edge(){}
	Edge(int a, int b, int next):a(a),b(b),next(next){}
}e[1000010];

int p[100010];
int tot;

void add(int a, int b) {
	e[tot] = Edge(a,b,p[a]);
	p[a]=tot++;
}

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],rmq[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[2][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
		path[id++] = t;
	}
}

void init() {
	for(int i = 0; i <id; ++i) {
		rmq[i][0] = path[i];
		//printf("i = %d path = %d\n",i,path[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 0; i < id; ++i) {
			rmq[i][j] = dep[rmq[i][j-1]]<dep[rmq[i+(1<<(j-1))][j-1]]?rmq[i][j-1]:rmq[i+(1<<(j-1))][j-1];
		}
	}
}

int lca(int a, int b) {
	if(in[a]>in[b]) swap(a,b);
	int s = in[a], e = in[b];
	int k = 0;
	for(; (1<<k)<=(e-s+1);++k);
	k--;
	//printf("a = %d b = %d s = %d e = %d k = %d\n",a,b,s,e,k);
	return dep[rmq[s][k]]<dep[rmq[e-(1<<k)+1][k]]?rmq[s][k]:rmq[e-(1<<k)+1][k];
}

int k,m,r;
int v[100010];
int num;
vector<int> nima;

void dfs1(int t, int fa) {
	//printf("dfs1 t = %d fa = %d num = %d %d\n",t,fa,num,v[t]);
	f[t] = num;
	if(v[t]){
		nima.pb(t);
		++num;
	}
	for(int i = p[t]; i !=-1; i = e[i].next) {
		if(e[i].b==fa)continue;
		dfs1(e[i].b,t);
	}

	if(v[t])--num;
}
int sol() {

	clr(v);
	auto cmp = [&](const int i, int j) {
		return in[i]<in[j];
	};

	int root = a[1];
	for(int i = 0; i < k; ++i) {
		v[a[i]]=1;
		root = lca(root, a[i]);
	}
	if(v[r]==0) {
		a[k++]=r;
	}
	if(!v[root])a[k++]=root;

	sort(a,a+k,cmp);

	stack<int> st;
	_clr(p);
	tot = 0;
	for(int i = 0; i < k;++i) {
		//printf("ft i = %d ft = %d\n",i,ft[i]);
		while(!st.empty()&&lca(a[i],st.top())!=st.top()) st.pop();
		if(st.size()){
			//printf("add %d %d\n",a[i],st.top());
			add(a[i],st.top());
			add(st.top(),a[i]);
		}
		st.push(a[i]);
	}
	num = 0;
	nima.clear();
	dfs1(r,r);

	clr(dp);
	dp[1][1] = 1;
	//printf("i = 0 a = %d\n",nima[0]);
	for(int i = 2; i <= nima.size(); ++i) {
		int index = i&1;
		int pre = index ^1;
		clr(dp[index]);
		for(int j = 1; j <=m; ++j) {
			dp[index][j] = (dp[pre][j-1] + dp[pre][j]*(j-f[nima[i-1]]))%mod;
			//printf("i = %d j = %d a = %d dp = %lld f = %d\n",i,j,nima[i-1],dp[index][j], f[nima[i-1]]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[(nima.size())&1][i])%mod;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],la[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[100010][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
	}

	path[id] = t;
	out[t] = id++;
}

void init() {
	for(int i = 1; i <=n; ++i) {
		la[i][0] = fa[i];
		//printf("i = %d fa = %d\n",i,fa[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 1; i <=n; ++i) {
			la[i][j] = la[ la[i][j-1] ][j-1];
			//printf("i = %d j = %d laj-1 = %d la = %d\n",i,j,la[i][j-1],la[i][j]);
		}
	}
}

int lca(int a, int b) {

	if(dep[a]<dep[b])swap(a,b);
	//printf("lca a = %d b = %d, depa = %d depb = %d\n",a,b,dep[a],dep[b]);
	for(int i = 20; i >=0;--i) {
		if(dep[la[a][i]]>=dep[b]) {
			//printf("a = %d i = %d la = %d\n",a,i,la[a][i]);
			a = la[a][i];
		}
	}
	//printf("a = %d b = %d\n",a,b);
	for(int i = 20; i >=0; --i) {
		//printf("i = %d a = %d b = %d f = %d %d\n",i,a,b,la[a][i],la[b][i]);
		if(la[a][i]!=la[b][i]) {
			//printf("i = %d a = %d b = %d f = %d %d\n",i,a,b,la[a][i],la[b][i]);
			a = la[a][i];
			b = la[b][i];
		}
	}
	//printf("a = %d b = %d\n",a,b);
	return la[a][0];
}

int k,m,r;

int sol() {

	auto cmp = [&](const int i, int j) {
		int lca_i = lca(i,r);
		int lca_j = lca(j,r);
		//printf("sort r = %d i = %d lca_I = %d j = %d lca_j = %d\n",r,i,lca_i,j,lca_j);
		if(lca_i==r&&lca_j==r) {
			return in[i]<in[j];
		}
		else if(lca_i==r&&lca_j!=r) {
			return false;
		}else if(lca_i!=r&&lca_j==r) {
			return true;
		}
		else {
			if(lca_i==lca_j) {
				return in[i]<in[j];
			}
			else if(lca_i==i||lca_j==j) {
				return dep[lca_i]>dep[lca_j];
			}
			else {
				return in[i]<in[j];
			}
		}
	};

	sort(a,a+k,cmp);

	stack<int> st;
	for(int i = 0; i < k; ++i) {
		int lca_i = lca(a[i],r);
		//printf("i = %d a = %d r = %d lca = %d\n",i,a[i],r,lca_i);
		while(!st.empty()) {
			int t = st.top();
			int lca_t = lca(t,r);
			//printf("st t = %d r = %d lca = %d\n",t,r,lca_t);
			if(lca_t == r && lca_i == r) {
				if(out[a[i]]>out[t]) {
					st.pop();
					continue;
				}
			}
			else if(lca_t==r &&lca_i!=r) {
				break;
			}
			else if(lca_t!=r && lca_i==r) {
				st.pop();
				continue;
			}
			else {
				if(lca_i==lca_t) {
					if(out[a[i]]>out[t]) {
						st.pop();
						continue;
					}
				}
				else if(lca_i == a[i] || lca_t == t) {
					if(dep[lca_t]<dep[lca_i]) {
						st.pop();
						continue;
					}
					else {
						if(lca_t !=t) {
							st.pop();
							continue;
						}
					}
				}
				else {
					if(out[a[i]]>out[t]) {
						st.pop();
						continue;
					}
				}
			}
			break;
		}
		f[i] = st.size();
		//printf("i = %d f i = %d\n",i,f[i]);
		st.push(a[i]);
	}

	dp[1][1] = 1;
	for(int i = 2; i <= k; ++i) {
		for(int j = 1; j <=m; ++j) {
			dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]*(j-f[i-1]))%mod;
			//printf("i = %d j = %d dp = %d f = %d\n",i,j,dp[i][j], f[i-1]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[k][i])%mod;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

struct Edge{
	int a,b,next;
	Edge(){}
	Edge(int a, int b, int next):a(a),b(b),next(next){}
}e[1000010];

int p[100010];
int tot;

void add(int a, int b) {
	e[tot] = Edge(a,b,p[a]);
	p[a]=tot++;
}

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],rmq[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[2][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
		path[id++] = t;
	}
}

void init() {
	for(int i = 0; i <id; ++i) {
		rmq[i][0] = path[i];
		//printf("i = %d path = %d\n",i,path[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 0; i < id; ++i) {
			rmq[i][j] = dep[rmq[i][j-1]]<dep[rmq[i+(1<<(j-1))][j-1]]?rmq[i][j-1]:rmq[i+(1<<(j-1))][j-1];
		}
	}
}

int lca(int a, int b) {
	if(in[a]>in[b]) swap(a,b);
	int s = in[a], e = in[b];
	int k = 0;
	for(; (1<<k)<=(e-s+1);++k);
	k--;
	//printf("a = %d b = %d s = %d e = %d k = %d\n",a,b,s,e,k);
	return dep[rmq[s][k]]<dep[rmq[e-(1<<k)+1][k]]?rmq[s][k]:rmq[e-(1<<k)+1][k];
}

int k,m,r;
int v[100010];
int num;
vector<int> nima;

void dfs1(int t, int fa) {
	//printf("dfs1 t = %d fa = %d num = %d %d\n",t,fa,num,v[t]);
	f[t] = num;
	if(v[t]){
		nima.pb(t);
		++num;
	}
	for(int i = p[t]; i !=-1; i = e[i].next) {
		if(e[i].b==fa)continue;
		dfs1(e[i].b,t);
	}

	if(v[t])--num;
}
int sol() {

	clr(v);
	auto cmp = [&](const int i, int j) {
		return in[i]<in[j];
	};

	for(int i = 0; i < k; ++i) {
		v[a[i]]=1;
	}
	if(v[r]==0) {
		a[k++]=r;
	}

	sort(a,a+k,cmp);

	int flag = 0;
	set<int> sb;
	vector<int> ft;
	for(int i = 0; i < k; ++i) {
		if(i==0) {
			ft.pb(a[i]);
			//sb.insert(a[i]);
		}
		else {
			int lca_i = lca(a[i],a[i-1]);
			//printf("lca i = %d i-1 = %d lca = %d\n",a[i],a[i-1],lca_i);
			//if(sb.find(lca_i)==sb.end()) {
			//	sb.insert(lca_i);
			if(lca_i!=ft[ft.size()-1])
				ft.pb(lca_i);
			//}
			//sb.insert(a[i]);
			if(a[i]!=ft[ft.size()-1])
				ft.pb(a[i]);
		}
	}

	sort(ft.begin(), ft.end(),cmp);
	stack<int> st;

	_clr(p);
	tot = 0;
	for(int i = 0; i < ft.size();++i) {
		//printf("ft i = %d ft = %d\n",i,ft[i]);
		while(!st.empty()&&lca(ft[i],st.top())!=st.top()) st.pop();
		if(st.size()){
			//printf("add %d %d\n",ft[i],st.top());
			add(ft[i],st.top());
			add(st.top(),ft[i]);
		}
		st.push(ft[i]);
	}
	num = 0;
	nima.clear();
	dfs1(r,r);

	clr(dp);
	dp[1][1] = 1;
	//printf("i = 0 a = %d\n",nima[0]);
	for(int i = 2; i <= nima.size(); ++i) {
		int index = i&1;
		int pre = index ^1;
		clr(dp[index]);
		for(int j = 1; j <=m; ++j) {
			dp[index][j] = (dp[pre][j-1] + dp[pre][j]*(j-f[nima[i-1]]))%mod;
			//printf("i = %d j = %d a = %d dp = %lld f = %d\n",i,j,nima[i-1],dp[index][j], f[nima[i-1]]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[(nima.size())&1][i])%mod;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}


#include <string.h>
#include <unordered_map>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include   <stdlib.h>
#include   <time.h>
#include <stack>
#include <queue>
#include <set>

#include <map>
#include <vector>
#include <string>
#include <stdlib.h>

#define ll long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf

#define pf printf
#define mp make_pair

using namespace std;
ll mod = 1000000007;
int n,q;

struct Edge{
	int a,b,next;
	Edge(){}
	Edge(int a, int b, int next):a(a),b(b),next(next){}
}e[1000010];

int p[100010];
int tot;

void add(int a, int b) {
	e[tot] = Edge(a,b,p[a]);
	p[a]=tot++;
}

vector<int> g[1000010];
int in[1000010],out[1000010],path[1000010],id;
int f[100010],rmq[1000010][21];
int fa[1000010],dep[1000010];
int a[1000010];
ll dp[2][301];

void dfs(int t, int f) {
	fa[t] = f;
	path[id]=t;
	in[t] = id++;
	dep[t] = dep[f]+1;

	for(int i : g[t]) {
		if(i==f)continue;
		dfs(i,t);
		path[id++] = t;
	}
}

void init() {
	for(int i = 0; i <id; ++i) {
		rmq[i][0] = path[i];
		//printf("i = %d path = %d\n",i,path[i]);
	}

	for(int j = 1; j <=20; ++j) {
		for(int i = 0; i < id; ++i) {
			rmq[i][j] = dep[rmq[i][j-1]]<dep[rmq[i+(1<<(j-1))][j-1]]?rmq[i][j-1]:rmq[i+(1<<(j-1))][j-1];
		}
	}
}

int lca(int a, int b) {
	if(in[a]>in[b]) swap(a,b);
	int s = in[a], e = in[b];
	int k = 0;
	for(; (1<<k)<=(e-s+1);++k);
	k--;
	//printf("a = %d b = %d s = %d e = %d k = %d\n",a,b,s,e,k);
	return dep[rmq[s][k]]<dep[rmq[e-(1<<k)+1][k]]?rmq[s][k]:rmq[e-(1<<k)+1][k];
}

int k,m,r;
int v[100010];
int num;
int nima[1000010];
int st[1000010];

void dfs1(int t, int fa) {
	//printf("dfs1 t = %d fa = %d num = %d %d\n",t,fa,num,v[t]);
	f[t] = num;
	if(v[t]){
		nima[k++]=t;
		++num;
	}
	for(int i = p[t]; i !=-1; i = e[i].next) {
		if(e[i].b==fa)continue;
		dfs1(e[i].b,t);
	}

	if(v[t])--num;
}

int sol() {

	auto cmp = [&](const int i, int j) {
		return in[i]<in[j];
	};

	int root = a[0];
	for(int i = 0; i < k; ++i) {
		v[a[i]]=1;
		root = lca(root, a[i]);
		//printf("root = %d ai = %d\n",root,a[i]);
	}
	//printf("root = %d\n",root);
	if(v[r]==0) {
		a[k++]=r;
	}
	if(!v[root])a[k++]=root;

	sort(a,a+k,cmp);

	int top = 0;
	_clr(p);
	tot = 0;
	for(int i = 0; i < k;++i) {
		//printf("ft i = %d ft = %d\n",i,a[i]);
		if(top==0) {
			st[top++]=a[i];
		}
		else {
			if(lca(a[i],a[i-1])==a[i-1]) {
				//printf("push 1 %d\n",a[i]);
				st[top++]=a[i];
			}
			else {
				int lca_t = lca(a[i], a[i-1]);
				while(top>1&&dep[st[top-2]]>dep[lca_t]) {
					//printf("add t = %d %d\n",st[top-1],st[top-2]);
					add(st[top-1],st[top-2]);
					add(st[top-2],st[top-1]);
					top--;
				}
				if(top>0&&dep[st[top-1]] > dep[lca_t]) {
					//printf("add lcat = %d %d\n",st[top-1],lca_t);
					add(st[top-1],lca_t);
					add(lca_t,st[top-1]);
					top--;
				}

				if(top==0||st[top-1] != lca_t) {
					//printf("push %d\n",lca_t);
					st[top++]=lca_t;
				}

				//printf("push %d\n",a[i]);
				st[top++]=a[i];
			}
		}
	}
	while(top>1) {
		//printf("add left = %d %d\n",st[top-1],st[top-2]);
		add(st[top-1],st[top-2]);
		add(st[top-2],st[top-1]);
		top--;
	}
	num = 0;
	k = 0;
	dfs1(r,r);

	clr(dp);
	dp[1][1] = 1;
	//printf("i = 0 a = %d\n",nima[0]);
	for(int i = 2; i <= k; ++i) {
		int index = i&1;
		int pre = index ^1;
		clr(dp[index]);
		for(int j = 1; j <=m; ++j) {
			dp[index][j] = (dp[pre][j-1] + dp[pre][j]*(j-f[nima[i-1]]))%mod;
			//printf("i = %d j = %d a = %d dp = %lld f = %d\n",i,j,nima[i-1],dp[index][j], f[nima[i-1]]);
		}
	}
	ll ans = 0;
	for(int i = 1; i<=m;++i) {
		ans = (ans + dp[k&1][i])%mod;
	}
	for(int i = 0; i < k; ++i) {
		v[nima[i]]=0;
	}
	return ans;
}

int main(){
	while(cin>>n>>q){
		fr(i,0,n-1) {
			int u,v;
			sf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		id = 0;
		dfs(1,1);
		/*
		for(int i = 0; i < id; ++i) {
			printf("%d ",path[i]);
		}
		for(int i = 1;i <=n; ++i) {
			printf("i = %d in = %d out = %d\n",i,in[i],out[i]);
		}
		*/
		init();
		fr(i,0,q) {
			sf("%d%d%d",&k,&m,&r);
			for(int j = 0; j < k; ++j) {
				sf("%d",&a[j]);
			}
			cout<<sol()<<endl;
		}
	}
}