#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_) for(int V_=(A_), V_##_END=(B_); V_>=V_##_END; V_--)
#ifdef _WIN32
#define long __int64
#endif
#if defined(_LOCAL_) && 0
#undef assert
#define assert(expr) ({ if(!(expr)) asm("int3"); 0; })
#endif
using namespace std;
const int MAXN=2010,MAXQ=5e5+10;
int n,m,qn; vector<int> G[MAXN];
int var(int i,int x){ return i*2+x; }
int neg(int u){ return u^1; }
struct TwoSat{
    static const int MAXN=1.6e7,MAXM=5.6e7;
    int nnd;
    struct{ int v,nxt; } E[MAXM]; int head[MAXN],ecnt;
    void _add(int u,int v){ E[++ecnt]={v,head[u]},head[u]=ecnt; }
    void add(int u,int v){ _add(u,v),_add(neg(v),neg(u)); }
    int dfn[MAXN],low[MAXN],dfnc,stk[MAXN],stkp,col[MAXN],ncol,sol[MAXN]; bool instk[MAXN];
    void tarjan(int u){
        dfn[u]=low[u]=++dfnc; stk[++stkp]=u,instk[u]=1;
        for(int i=head[u]; i; i=E[i].nxt){
            int v=E[i].v;
            if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
            else if(instk[v]) low[u]=min(low[u],dfn[v]);
        }
        if(dfn[u]==low[u]){
            col[u]=++ncol,instk[u]=0;
            int v;
            while((v=stk[stkp--])!=u) col[v]=ncol,instk[v]=0;
        }
    }
    bool solve(){
        RNG(u,2,2*nnd+1){
            if(!dfn[u]) tarjan(u);
        }
        RNG(i,1,nnd){
            if(col[var(i,0)]==col[var(i,1)]) return 0;
            sol[i]=col[var(i,1)]<col[var(i,0)];
        }
    }
} ts;
struct DSU{
    int fa[MAXN];
    void init(){ iota(fa+1,fa+m+1,1); }
    int find(int u){ return u==fa[u]?u:fa[u]=find(fa[u]); }
    void merge(int u,int v){
        if((u=find(u))!=(v=find(v))) fa[v]=u;
    }
} dsu[MAXN][11];
int dfn[MAXN],dfnc,fa[MAXN][11],dep[MAXN];
void dfs1(int u,int fa_){
    fa[u][0]=fa_,dfn[u]=++dfnc,dep[u]=dep[fa_]+1;
    RNG(i,1,__lg(dep[u])) fa[u][i]=fa[fa[u][i-1]][i-1],dsu[u][i].init();
    for(int v:G[u]){
        if(v!=fa_) dfs1(v,u);
    }
}
int lca(int u,int v){
    if(dep[u]<dep[v]) swap(u,v);
    int d=dep[u]-dep[v];
    RNG(i,0,10){
        if((d>>i)&1) u=fa[u][i];
    }
    if(u==v) return u;
    IRNG(i,10,1){
        if(fa[u][i]!=fa[v][i]) u=fa[u][i],v=fa[v][i];
    }
    return fa[u][0];
}
void upd(int u,int d,vector<int>& S){
    if(!d||S.sie()==1) return;
    IRNG(i,10,0){
        if((d>>i)&1){
            RNG(j,1,int(S.size())-1) dsu[u][i].merge(S[0],S[j]);
            u=fa[u][i];
        }
    }
}
void dfs2(int u){
    for(auto v:G[u]){
        if(v!=fa[u][0]) dfs2(v);
    }
    IRNG(i,__lg(dep[u]),1){
        int v=fa[u][i-1];
        RNG(x,1,m,y){
            if((y=dsu[u][i].find(x))!=x) dsu[u][i-1].merge(x,y),dsu[v][i-1].merge(x,y);
        }
    }
}
int id[MAXN][MAXN];
vector<int> A[MAXN];
struct{ vector<int> U,S; } Q[MAXN];
int main(){
#if defined(_LOCAL_)
    freopen("in","r",stdin);
//  freopen("out","w",stdout);
#else
    freopen("wukong.in","r",stdin);
    freopen("wukong.out","w",stdout);
#endif
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>m>>qn;
    RNG(_,1,n-1,u,v) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
    RNG(i,1,m){
        int k; cin>>k; A[i].resize(k);
        for(int u:A[i]) cin>>u;
    }
    RNG(i,1,qn){
        int k; cin>>k; Q[i].U.resize(k);
        for(int u:Q[i].U) cin>>u;
        cin>>k; Q[i].S.resize(k);
        for(int x:Q[i].S) cin>>x;
    }
    dfs1(1,0);
    RNG(i,1,qn){
        auto& U=Q[i].U;
        sort(U.begin(),U.end(),[](int u,int v){ return dfn[u]<dfn[v]; });
        RNG(i,1,int(U.size())-1){
            int u=U[i-1],v=U[i],w=lca(u,v);
            upd(u,dep[u]-dep[w],Q[i].S),upd(v,dep[v]-dep[w],Q[i].S);
        }
    }
    dfs2(1);
    RNG(u,2,n){
        RNG(i,1,m){
            if(int& x=id[i][dsu[u][0].find(i)]; !x) x=++ts.nnd,id[i][u]=x;
        }
    }
}