#include <iostream>
#include <queue>
#define int long long
using namespace std;
const int N=3e5+5;
int a[N];
priority_queue<pair<int,int>> q[N];
priority_queue<pair<int,int>> t;
priority_queue<pair<int,int>> del1[N];
priority_queue<pair<int,int>> del2;
int f[N];
int tag1[N],tag2;
int find(int x){
return f[x]==x ? x : f[x]=find(f[x]);
}
void update1(int idx){
idx=find(idx);
while (!del1[idx].empty() && !q[idx].empty() && q[idx].top()==del1[idx].top()){
del1[idx].pop();
q[idx].pop();
}
}
void update2(){
while (!del2.empty() && !t.empty() && t.top()==del2.top()){
t.pop();
del2.pop();
}
}
void debug(){
priority_queue<pair<int,int>> qwq=t;
while (!qwq.empty()){
cout<<qwq.top().first<<" "<<qwq.top().second<<endl;
qwq.pop();
}
}
signed main(){
int n;
cin >> n;
for (int i=1;i<=n;++i){
scanf("%lld",&a[i]);
f[i]=i;
q[i].emplace(a[i],i);
t.emplace(a[i],i);
}
int u,v,w;
char op;
int m;
cin >> m;
pair<int,int> p;
for (int _=0;_<m;++_){
op=getchar();
while (op==' ' || op=='\n' || op=='\r' || op==EOF){
op=getchar();
}
if (op=='U'){
scanf("%lld%lld",&u,&v);
u=find(u),v=find(v);
if (u==v){
continue;
}
if (q[u].size()>q[v].size()){
swap(u,v);
}
update1(u);
while (!q[u].empty()){
update1(u);
p=q[u].top();
q[u].pop();
a[p.second]+=tag1[u];
a[p.second]-=tag1[v];
p.first=a[p.second];
q[v].emplace(a[p.second],p.second);
update1(u);
}
update1(v);
f[u]=v;
}else if (op=='A'){
op=getchar();
if (op=='1'){
scanf("%lld%lld",&u,&w);
del1[find(u)].emplace(a[u],u);
del2.emplace(a[u]+tag1[find(u)],u);
a[u]+=w;
q[find(u)].emplace(a[u],u);
t.emplace(a[u]+tag1[find(u)],u);
}else if (op=='2'){
scanf("%lld%lld",&u,&w);
u=find(u);
update1(u);
p=q[u].top();
del2.emplace(p);
tag1[u]+=w;
p.first+=w;
t.emplace(p);
}else{
scanf("%lld",&w);
tag2+=w;
}
}else{
op=getchar();
if (op=='1'){
scanf("%lld",&u);
printf("%lld\n",a[u]+tag1[find(u)]+tag2);
}else if (op=='2'){
scanf("%lld",&u);
u=find(u);
update1(u);
p=q[u].top();
printf("%lld\n",p.first+tag1[u]+tag2);
}else{
update2();
p=t.top();
printf("%lld\n",p.first+tag2);
}
}
}
return 0;
}