1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <cstring>
5 #define rep(i,l,r) for(int i=l; i<=r; i++)
6 #define clr(x,y) memset(x,y,sizeof(x))
7 #define travel(x) for(Edge *p=last[x]; p; p=p->pre)
8 using namespace std;
9 const int INF = 0x3f3f3f3f;
10 const int maxn = 100010;
11 inline int read(){
12 int ans = 0, f = 1;
13 char c = getchar();
14 for(; !isdigit(c); c = getchar())
15 if (c == ‘-‘) f = -1;
16 for(; isdigit(c); c = getchar())
17 ans = ans * 10 + c - ‘0‘;
18 return ans * f;
19 }
20 int n,m,q,x,y,fa[maxn];
21 char ch[10];
22 struct Node{
23 Node *ch[2]; int s,v,r,n;
24 inline void maintain(){
25 s = ch[0]->s + ch[1]->s + 1;
26 }
27 }treap[250010];
28 Node *pt = treap, *null = pt++, *root[maxn];
29 inline Node *newnode(int x,int y){
30 pt->s = 1; pt->v = x; pt->n = y; pt->r = rand();
31 pt->ch[0] = pt->ch[1] = null;
32 return pt++;
33 }
34 inline void rotate(Node *&o,int d){
35 Node *k = o->ch[d^1]; o->ch[d^1] = k->ch[d]; k->ch[d] = o;
36 o->maintain(); k->maintain(); o = k;
37 }
38 void ins(int x,int y,Node *&p){
39 if (p == null) p = newnode(x,y);
40 else{
41 int d = x > p->v;
42 ins(x,y,p->ch[d]);
43 if (p->ch[d]->r < p->r) rotate(p,d^1);
44 }
45 p->maintain();
46 }
47 int select(int x,Node *p){
48 for(; ;){
49 int t = p->ch[0]->s;
50 if (x == t + 1) return p->n;
51 else if (x <= t) p = p->ch[0];
52 else x -= t + 1, p = p->ch[1];
53 }
54 }
55 void merge(Node *&x,Node *&y){
56 if (x == null) return;
57 merge(x->ch[0],y); merge(x->ch[1],y);
58 ins(x->v,x->n,y);
59 }
60 int getfa(int x){
61 return x == fa[x] ? x : fa[x] = getfa(fa[x]);
62 }
63 void join(int x,int y){
64 int a = getfa(x), b = getfa(y);
65 if (a == b) return;
66 if (root[a]->s > root[b]->s) swap(a,b);
67 fa[a] = b;
68 merge(root[a],root[b]);
69 }
70 int query(int x,int y){
71 int a = getfa(x);
72 if (y > root[a]->s) return -1;
73 return select(y,root[a]);
74 }
75 int main(){
76 n = read(); m = read(); null->s = 0;
77 rep(i,1,n) root[i] = null; rep(i,1,n) fa[i] = i;
78 rep(i,1,n){
79 x = read(); ins(x,i,root[i]);
80 }
81 rep(i,1,m){
82 x = read(); y = read();
83 join(x,y);
84 }
85 q = read();
86 rep(i,1,q){
87 scanf("%s",ch); x = read(); y = read();
88 if (ch[0] == ‘B‘) join(x,y);
89 else printf("%d\n",query(x,y));
90 }
91 return 0;
92 }