#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class tim>
void operator +=(vec<tim> &a,tim b){a.push_back(b);}
template<class tim>
void operator --(vec<tim> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define inf (long long)(1e18)
template<class tim>
bool Min(tim &x,tim y){return x>y?x=y,1:0;}
template<class tim>
bool Max(tim &x,tim y){return x<y?x=y,1:0;}
const int mod=998244353;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
int n,m,q,p[100010],b[100010],qx[100010],qy[100010];
pii lsh[500010];
int tot;
vec<int> tim[500010];
int id(int x,int y){
int i=lb(lsh+1,lsh+tot+1,pii{x,y})-lsh;
assert(lsh[i].x==x&&lsh[i].y==y);
return i;
}
map<int,int> cha;
void work(){
cin>>n>>m>>q;
iota(p+1,p+n+2,1);
for(int i=1;i<n;i++){
lsh[++tot]={i,i+1};
}
for(int i=1,x,y;i<=m;i++){
cin>>qx[i]>>qy[i];
x=qx[i],y=qy[i];
if(x>y)swap(x,y);
swap(p[x],p[y]);
if(x>1)lsh[++tot]={p[x-1],p[x]};
lsh[++tot]={p[x],p[x+1]};
if(x+1<y){
lsh[++tot]={p[y-1],p[y]};
}
if(y<n){
lsh[++tot]={p[y],p[y+1]};
}
}
sort(lsh+1,lsh+tot+1);
tot=unique(lsh+1,lsh+tot+1)-lsh-1;
iota(p+1,p+n+2,1);
for(int i=1;i<n;i++){
tim[id(i,i+1)]+=0;
}
for(int i=1;i<=m;i++){
int x=qx[i],y=qy[i];
if(x>y)swap(x,y);
if(x>1)tim[id(p[x-1],p[x])]+=i;
tim[id(p[x],p[x+1])]+=i;
if(x+1<y){
tim[id(p[y-1],p[y])]+=i;
}
if(y<n){
tim[id(p[y],p[y+1])]+=i;
}
swap(p[x],p[y]);
if(x>1)tim[id(p[x-1],p[x])]+=i;
tim[id(p[x],p[x+1])]+=i;
if(x+1<y){
tim[id(p[y-1],p[y])]+=i;
}
if(y<n){
tim[id(p[y],p[y+1])]+=i;
}
}
for(int i=1;ik<=tot;i++){
assert(siz(tim[i])<=10000);
}
while(q--){
cin>>m;
for(int i=1;i<=m;i++){
cin>>b[i];
}
if(m==1)cout<<"0\n";
else{
cha.clear();
for(int i=1;i<m;i++){
// assert(siz(tim[id(b[i],b[i+1])])<=3000);
for(int j=0;j<siz(tim[id(b[i],b[i+1])]);j++){
if(~j&1){
++cha[tim[id(b[i],b[i+1])][j]];
}else{
--cha[tim[id(b[i],b[i+1])][j]];
}
}
}
int s=0;
for(auto [x,y]:cha){
s+=y;
if(s==m-1){
cout<<x<<'\n';
break;
}
}
}
}
}
bool Med;
signed main(){
int T=1;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'tim KNOW WHAT TO DO
- STOP TYPING IF YOU DON'tim KNOW WHAT YOU'RE DOING
*/