#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 210000
#define MAXV 210000
#define MAXE 420000
#define MAXT 4010000
#define MAXQ 310000
int n,m;
int vv[MAXN];
int avv[MAXN];
struct Edge
{
int np,val;
Edge *next;
}E[MAXE],*V[MAXV];
int tope=-1;
void addedge(int x,int y)
{
//cout<<"Add: "<<x<<" "<<y<<endl;
E[++tope].np=y;
E[tope].next=V[x];
V[x]=&E[tope];
}
int uf[MAXN];
int topn;
int get_fa(int now)
{
return (uf[now]==now)?now:(uf[now]=get_fa(uf[now]));
}
int comb(int x,int y)
{
x=get_fa(x);
y=get_fa(y);
if (x==y)return false;
topn++;
// addedge(x,topn);
addedge(topn,x);
// addedge(y,topn);
addedge(topn,y);
uf[x]=topn;
uf[y]=topn;
uf[topn]=topn;
return topn;
}
struct qur_t
{
int x,y;
int val;
char opt;
}qur[MAXQ];
int q[MAXN],topq;
int fa[MAXN];
int siz[MAXN];
int pos[MAXN];
int sub_s[MAXN],sub_t[MAXN];
void bfs(int rt)
{
int head=-1,tail=0;
Edge *ne;
int now;
int i;
q[0]=rt;
while (head<tail)
{
now=q[++head];
for (ne=V[now];ne;ne=ne->next)
{
fa[ne->np]=now;
q[++tail]=ne->np;
}
}
topq=tail;
for (i=topq;i>=0;i--)
{
siz[q[i]]=V[q[i]]==0;
for (ne=V[q[i]];ne;ne=ne->next)
{
siz[q[i]]+=siz[ne->np];
}
}
pos[rt]=1;
int x;
for (i=0;i<=topq;i++)
{
now=q[i];
x=pos[now];
sub_s[now]=x;
for(ne=V[now];ne;ne=ne->next)
{
pos[ne->np]=x;
x+=siz[ne->np];
}
x+=V[now]==0;
sub_t[now]=x-1;
if (V[now])pos[now]=-1;
}
}
struct sgt_node
{
int lch,rch,sum;
}sgt[MAXT];
int root[MAXN];
int topt=0;
void Add_val(int base,int &now,int l,int r,int pos,int v)
{
now=++topt;
sgt[now]=sgt[base];
if (l==r)
{
sgt[now].sum+=v;
return ;
}
if (pos<=((l+r)>>1))
{
Add_val(sgt[base].lch,sgt[now].lch,l,(l+r)>>1,pos,v);
}else
{
Add_val(sgt[base].rch,sgt[now].rch,((l+r)>>1)+1,r,pos,v);
}
sgt[now].sum=sgt[sgt[now].lch].sum+sgt[sgt[now].rch].sum;
}
int Qry_kth(int lt,int rt,int rk)
{
lt=root[lt-1];
rt=root[rt];
if (sgt[rt].sum-sgt[lt].sum<rk)return -1;
int l,r,mid;
l=1,r=n;
while (l!=r)
{
mid=(l+r)>>1;
if (sgt[sgt[rt].lch].sum-sgt[sgt[lt].lch].sum<rk)
{
rk-=sgt[sgt[rt].lch].sum-sgt[sgt[lt].lch].sum;
rt=sgt[rt].rch;
lt=sgt[lt].rch;
l=mid+1;
}else
{
rt=sgt[rt].lch;
lt=sgt[lt].lch;
r=mid;
}
}
return avv[l];
}
int v2[MAXN];
int bb[MAXN][2];
int main()
{
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int i,j,k,x,y,z;
scanf("%d%d",&n,&m);
for (i=0;i<=n;i++)uf[i]=i;
for (i=0;i<n;i++)
{
scanf("%d",&vv[i+1]);
avv[vv[i+1]]=i+1;
}
topn=n;
for (i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
bb[i][0]=x;
bb[i][1]=y;
comb(x,y);
}
int q;
scanf("%d\n",&q);
char opt;
for (i=0;i<q;i++)
{
scanf("%c%d%d\n",&qur[i].opt,&qur[i].x,&qur[i].y);
if (qur[i].opt==‘B‘)
qur[i].val=comb(qur[i].x,qur[i].y);
}
topn++;
uf[topn]=topn;
for (i=1;i<=n;i++)
{
if (get_fa(i)!=topn)
{
addedge(topn,get_fa(i));
uf[get_fa(i)]=topn;
}
}
bfs(topn);
for (i=1;i<=n;i++)
{
v2[pos[i]]=vv[i];
}
for (i=1;i<=n;i++)
{
Add_val(root[i-1],root[i],1,n,v2[i],1);
}
topn=n;
for (i=0;i<=n;i++)
uf[i]=i;
//cout<<"---------------------------------------------"<<endl;
for (i=0;i<m;i++)
{
comb(bb[i][0],bb[i][1]);
}
for (i=0;i<q;i++)
{
if (qur[i].opt==‘Q‘)
{
printf("%d\n",Qry_kth(sub_s[get_fa(qur[i].x)],sub_t[get_fa(qur[i].x)],qur[i].y));
}else
{
comb(qur[i].x,qur[i].y);
}
}
return 0;
}