#include<cstdio>
#include<iostream>
#define N 30010
using namespace std;
int fa[N],son[N][2],rev[N],v[N],sum[N],st[N],n,m;
bool isroot(int x){
return son[fa[x]][0]!=x&&son[fa[x]][1]!=x;
}
void pushup(int x){
sum[x]=sum[son[x][0]]+sum[son[x][1]]+v[x];
}
void pushdown(int x){
if(!rev[x]) return;
rev[son[x][0]]^=1;rev[son[x][1]]^=1;
swap(son[x][0],son[x][1]);rev[x]=0;
}
void rotate(int x){
int y=fa[x],z=fa[y],l,r;
if(son[y][0]==x) l=0;else l=1;r=l^1;
if(!isroot(y)){
if(son[z][0]==y) son[z][0]=x;
else son[z][1]=x;
}
fa[x]=z;fa[y]=x;fa[son[x][r]]=y;
son[y][l]=son[x][r];son[x][r]=y;
pushup(y);pushup(x);
}
void splay(int x){
int top=0;st[++top]=x;
for(int i=x;!isroot(i);i=fa[i])
st[++top]=fa[i];
for(int i=top;i;i--) pushdown(st[i]);
while(!isroot(x)){
int y=fa[x],z=fa[y];
if(!isroot(y)){
if((son[z][0]==y)^(son[y][0]==x)) rotate(x);
else rotate(y);
}
rotate(x);
}
}
void access(int x){
int t=0;
while(x){
splay(x);
son[x][1]=t;
pushup(x);
t=x;x=fa[x];
}
}
void makeroot(int x){
access(x);
splay(x);
rev[x]^=1;
}
void join(int x,int y){
makeroot(x);
fa[x]=y;
splay(x);
}
void cut(int x,int y){
makeroot(x);
access(x);
splay(x);
son[y][0]=fa[x]=0;
pushup(y);
}
int find(int x){
access(x);splay(x);
while(son[x][0]) x=son[x][0];
return x;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&v[i]);
sum[i]=v[i];
}
scanf("%d",&m);
char opt[20];int x,y;
for(int i=1;i<=m;i++){
scanf("%s%d%d",opt,&x,&y);
if(opt[0]==‘b‘){
if(find(x)!=find(y)){
printf("yes\n");
join(x,y);
}
else printf("no\n");
}
else if(opt[0]==‘p‘){
makeroot(x);v[x]=y;
pushup(x);
}
else {
if(find(x)==find(y)){
makeroot(x);
access(y);
splay(y);
printf("%d\n",sum[y]);
}
else printf("impossible\n");
}
}
return 0;
}