1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #define maxn 100002
7 using namespace std;
8 char ch;
9 bool ok;
10 void read(int &x){
11 for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1;
12 for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar());
13 if (ok) x=-x;
14 }
15 int n,m,q,a,b,k,x,fa[maxn],root[maxn];
16 struct seg{
17 int idx,son[maxn*18][2],cnt[maxn*18],id[maxn*18];
18 void insert(int &k,int l,int r,int x,int num){
19 if (!k) k=++idx;
20 cnt[k]++;
21 if (l==r){id[k]=num;return;}
22 int m=(l+r)>>1;
23 if (x<=m) insert(son[k][0],l,m,x,num);
24 else insert(son[k][1],m+1,r,x,num);
25 }
26 int merge(int a,int b){
27 if (!a||!b) return a+b;
28 cnt[a]+=cnt[b];
29 son[a][0]=merge(son[a][0],son[b][0]);
30 son[a][1]=merge(son[a][1],son[b][1]);
31 return a;
32 }
33 void query(int a,int k){
34 if (cnt[a]<k){puts("-1");return;}
35 int l=1,r=n,m;
36 while (l!=r){
37 m=(l+r)>>1;
38 if (cnt[son[a][0]]>=k) a=son[a][0],r=m;
39 else k-=cnt[son[a][0]],a=son[a][1],l=m+1;
40 }
41 printf("%d\n",id[a]);
42 }
43 }T;
44 int find(int x){return fa[x]==x?fa[x]:fa[x]=find(fa[x]);}
45 void merge(int a,int b){
46 if (find(a)==find(b)) return;
47 root[find(a)]=T.merge(root[find(a)],root[find(b)]);
48 fa[find(b)]=find(a);
49 }
50 void query(int a,int k){T.query(root[find(a)],k);}
51 int main(){
52 read(n),read(m);
53 for (int i=1;i<=n;i++) read(x),T.insert(root[i],1,n,x,i);
54 for (int i=1;i<=n;i++) fa[i]=i;
55 for (int i=1;i<=m;i++) read(a),read(b),merge(a,b);
56 for (read(q);q;q--){
57 for (;ch!=‘Q‘&&ch!=‘B‘;ch=getchar());
58 if (ch==‘Q‘) read(a),read(k),query(a,k);
59 else read(a),read(b),merge(a,b);
60 }
61 return 0;
62 }