#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define pa t[x].fa
#define lc t[x].ch[0]
#define rc t[x].ch[1]
const int N=3e4+5;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();}
    return x*f;
}
struct node{
    int ch[2],fa,rev;
    int sum,w;
}t[N];
inline void update(int x){t[x].sum=t[lc].sum+t[rc].sum+t[x].w;}
inline int wh(int x){return t[pa].ch[1]==x;}
inline int isRoot(int x){return t[pa].ch[0]!=x&&t[pa].ch[1]!=x;}
inline void pushDown(int x){
    if(t[x].rev){
        t[lc].rev^=1;
        t[rc].rev^=1;
        swap(lc,rc);
        t[x].rev=0;
    }
}
inline void rotate(int x){
    int f=t[x].fa,g=t[f].fa,c=wh(x);
    if(!isRoot(f)) t[g].ch[wh(f)]=x;t[x].fa=g;
    t[f].ch[c]=t[x].ch[c^1];t[t[f].ch[c]].fa=f;
    t[x].ch[c^1]=f;t[f].fa=x;
    update(f);update(x);
}
int st[N],top;
inline void splay(int x){
    top=0;st[++top]=x;
    for(int i=x;!isRoot(i);i=t[i].fa) st[++top]=t[i].fa;
    for(int i=top;i>=1;i--) pushDown(st[i]);
    
    for(;!isRoot(x);rotate(x))
        if(!isRoot(pa)) rotate(wh(x)==wh(pa)?pa:x);
}
inline void Access(int x){
    for(int y=0;x;y=x,x=pa){
        splay(x);
        rc=y;
        update(x);
    }
}
inline void MakeRoot(int x){
    Access(x);
    splay(x);
    t[x].rev^=1;
}
inline int FindRoot(int x){
    Access(x);
    splay(x);
    while(lc) x=lc;
    return x;
}
inline void Link(int x,int y){
    MakeRoot(x);
    t[x].fa=y;
    splay(x);
}
int n,Q,x,y;
char s[N];
int main(){
    //freopen("in.txt","r",stdin);
    n=read();
    for(int i=1;i<=n;i++) t[i].w=t[i].sum=read();
    Q=read();
    while(Q--){
        scanf("%s",s);x=read();y=read();
        if(s[0]==‘b‘){
            if(FindRoot(x)==FindRoot(y)) puts("no");
            else puts("yes"),Link(x,y);
        }else if(s[0]==‘p‘){
            t[x].w=y;
            //Access(x);
            splay(x);
        }else{
            if(FindRoot(x)!=FindRoot(y)) puts("impossible");
            else{
                MakeRoot(x);Access(y);splay(y);
                printf("%d\n",t[y].sum);
            }
        }
    }
}