#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 3000010
int n,m;
int size[N],fa[N],tag[N],st[N],key[N],sum[N];
int child[N][2];
void update(int x)
{
sum[x]=sum[child[x][0]]+sum[child[x][1]]+key[x];
}
void pushdown(int x)
{
if(!tag[x]) return;
tag[x]^=1;
swap(child[x][0],child[x][1]);
tag[child[x][0]]^=1;
tag[child[x][1]]^=1;
}
bool isroot(int x)
{
return (!fa[x]||(child[fa[x]][0]!=x&&child[fa[x]][1]!=x));
}
void zig(int x)
{
int y=fa[x];
fa[x]=fa[y];
if(!isroot(y)) child[fa[x]][child[fa[x]][1]==y]=x;
child[y][0]=child[x][1]; fa[child[x][1]]=y;
child[x][1]=y; fa[y]=x;
update(y); update(x);
}
void zag(int x)
{
int y=fa[x];
fa[x]=fa[y];
if(!isroot(y)) child[fa[x]][child[fa[x]][1]==y]=x;
child[y][1]=child[x][0]; fa[child[x][0]]=y;
child[x][0]=y; fa[y]=x;
update(y); update(x);
}
void splay(int x)
{
int top=0; st[++top]=x;
for(int y=x;!isroot(y);y=fa[y]) st[++top]=fa[y];
for(int i=top;i;i--) pushdown(st[i]);
while(!isroot(x))
{
int y=fa[x],z=fa[y];
if(isroot(y))
{
child[y][0]==x?zig(x):zag(x); break;
}
child[y][0]==x?zig(x):zag(x);
child[z][0]==x?zig(x):zag(x);
}
}
void access(int x)
{
for(int t=0;x;t=x,x=fa[x])
{
splay(x);
child[x][1]=t;
update(x);
}
}
void rever(int x)
{
access(x); splay(x); tag[x]^=1;
}
void link(int x,int y)
{
rever(x); fa[x]=y;
update(x); update(y);
}
void cut(int x,int y)
{
rever(x); access(y); splay(y); child[y][0]=fa[x]=0;
update(x); update(y);
}
int find(int x)
{
access(x); splay(x);
for(;child[x][0];x=child[x][0]);
return x;
}
void query1(int x,int y)
{
if(find(x)==find(y))
{
printf("no\n");
return;
}
printf("yes\n");
link(x,y);
}
void change(int x,int y)
{
key[x]=y; splay(x);
}
void query2(int x,int y)
{
if(find(x)!=find(y))
{
printf("impossible\n");
return;
}
rever(x); access(y); splay(x);
printf("%d\n",sum[x]);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&key[i]);
update(i);
}
scanf("%d",&m);
while(m--)
{
char s[10]; int x,y; scanf("%s",s);
if(s[0]==‘b‘)
{
scanf("%d%d",&x,&y); query1(x,y);
}
if(s[0]==‘p‘)
{
scanf("%d%d",&x,&y); change(x,y);
}
if(s[0]==‘e‘)
{
scanf("%d%d",&x,&y); query2(x,y);
}
}
return 0;
}