1 #include <bits/stdc++.h>
2 #define Maxn 1000007
3 using namespace std;
4 int read()
5 {
6 int x=0,f=1;char ch=getchar();
7 while (ch<‘0‘||ch>‘9‘){if (ch==‘-‘) f=-1;ch=getchar();}
8 while (ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
9 return x*f;
10 }
11 int n,m;
12 int ls[Maxn],rs[Maxn];
13 int v[Maxn];
14 int fa[Maxn],d[Maxn];
15 bool vis[Maxn];
16 char ch[10];
17 int find(int x)
18 {
19 if (x==fa[x]) return fa[x];
20 fa[x]=find(fa[x]);
21 return fa[x];
22 }
23 int merge(int x,int y)
24 {
25 if (x==0) return y;
26 if (y==0) return x;
27 if (v[x]>v[y]) swap(x,y);
28 rs[x]=merge(rs[x],y);
29 if (d[rs[x]]>d[ls[x]]) swap(ls[x],rs[x]);
30 d[x]=d[rs[x]]+1;
31 return x;
32 }
33 int main()
34 {
35 n=read();
36 for (int i=1;i<=n;i++)
37 v[i]=read();
38 for (int i=1;i<=n;i++)
39 {
40 fa[i]=i;
41 d[i]=1;
42 }
43 memset(vis,true,sizeof(vis));
44 m=read();
45 while (m--)
46 {
47 scanf("%s",ch);
48 if (ch[0]==‘M‘)
49 {
50 int x=read(),y=read();
51 if ((!vis[x])||(!vis[y])) continue;
52 int p=find(x),q=find(y);
53 if (p!=q) fa[p]=fa[q]=merge(p,q);
54 } else
55 {
56 int x=read();
57 if (!vis[x])
58 {
59 printf("%d\n",0);
60 continue;
61 }
62 int p=find(x);
63 vis[p]=false;
64 printf("%d\n",v[p]);
65 fa[p]=merge(ls[p],rs[p]);
66 fa[fa[p]]=fa[p];
67 }
68 }
69 return 0;
70 }