1 var
  2   i,j,k,l,n,m,dts,y,a,b:longint;
  3   fa,sm,v,rev,dt:array[0..50001]of longint;
  4   ch:array[0..50001,0..1]of longint;
  5   ch1,ch2:char;
  6 procedure update(x:longint);
  7 begin
  8   if x=0 then exit; sm[x]:=v[x];
  9   if ch[x,0]<>0 then sm[x]:=sm[x]+sm[ch[x,0]];
 10   if ch[x,1]<>0 then sm[x]:=sm[x]+sm[ch[x,1]];
 11 end;
 12 function isroot(x:longint):boolean;
 13 begin
 14   if(x=0)or(fa[x]=0)then exit(true);
 15   exit((x<>ch[fa[x],0])and(x<>ch[fa[x],1]));
 16 end;
 17 procedure pushdown(x:longint);
 18 var tt:longint;
 19 begin
 20   if rev[x]=1 then
 21   begin
 22     tt:=ch[x,1]; ch[x,1]:=ch[x,0]; ch[x,0]:=tt; rev[x]:=0;
 23     if ch[x,0]<>0 then rev[ch[x,0]]:=rev[ch[x,0]]xor 1;
 24     if ch[x,1]<>0 then rev[ch[x,1]]:=rev[ch[x,1]]xor 1;
 25   end;
 26 end;
 27 procedure rotate(x:longint);
 28 var a1,a2,a3,b1,b2,b3:longint;
 29 begin
 30   if(x=0)or(isroot(x))then exit;
 31   a1:=fa[x]; a2:=fa[fa[x]];
 32   if x=ch[a1,1] then b1:=1 else b1:=0;
 33   if a1=ch[a2,1] then b2:=1 else b2:=0;
 34   if isroot(a1)then b3:=1 else b3:=0; a3:=ch[x,1-b1];
 35   if b3=0 then ch[a2,b2]:=x; fa[x]:=a2; ch[a1,b1]:=a3;
 36   if a3>0 then fa[a3]:=a1; ch[x,1-b1]:=a1; fa[a1]:=x;
 37   update(a1); update(x); if b3=0 then update(a2);
 38 end;
 39 procedure splay(x:longint);
 40 begin
 41   if x=0 then exit; dts:=0; y:=x;
 42   while not isroot(y) do begin inc(dts); dt[dts]:=y; y:=fa[y]; end;
 43   inc(dts); dt[dts]:=y; while dts>0 do begin pushdown(dt[dts]); dec(dts); end;
 44   while not isroot(x) do
 45   begin
 46     if not isroot(fa[x]) then
 47     begin
 48       if(x=ch[fa[x],1])xor(fa[x]=ch[fa[fa[x]],1])
 49       then rotate(x) else rotate(fa[x]);
 50     end;
 51     rotate(x);
 52   end;
 53 end;
 54 function access(x:longint):longint;
 55 var t:longint;
 56 begin
 57   if x=0 then exit(0); t:=0;
 58   while x>0 do
 59   begin
 60     splay(x); ch[x,1]:=t; update(x);
 61     if t>0 then fa[t]:=x; t:=x; x:=fa[x];
 62   end;
 63   exit(t);
 64 end;
 65 procedure cut(x,y:longint);
 66 begin
 67   if(x=0)and(y=0)then exit;
 68   access(x); splay(x); rev[x]:=rev[x]xor 1;
 69   access(y); splay(x); fa[y]:=0; ch[x,1]:=0; update(x);
 70 end;
 71 procedure link(x,y:longint);
 72 begin
 73   if(x=0)and(y=0)then exit;
 74   access(x); splay(x); rev[x]:=rev[x]xor 1; fa[x]:=y;
 75 end;
 76 function qsum(x,y:longint):longint;
 77 var a:longint;
 78 begin
 79   if(x=0)or(y=0)then exit(0); if x=y then exit(v[x]);
 80   access(x); a:=access(y); splay(x);
 81   if x=a then exit(v[a]+sm[ch[a,1]])else exit(sm[x]+v[a]+sm[ch[a,1]]);
 82 end;
 83 procedure change(x,y:longint);
 84 begin
 85   splay(x); v[x]:=y; update(x);
 86 end;
 87 function find(x:longint):longint;
 88 begin
 89   access(x); splay(x); while ch[x,0]>0 do x:=ch[x,0]; exit(x);
 90 end;
 91 begin
 92   readln(n); for i:=1 to n do read(v[i]); sm[i]:=v[i]; readln(m);
 93   for i:=1 to m do
 94   begin
 95     read(ch1); read(ch2); while ch2<>‘ ‘ do read(ch2); readln(a,b);
 96     if ch1=‘b‘ then
 97     begin
 98       if find(a)=find(b) then writeln(‘no‘)else
 99       begin writeln(‘yes‘); link(a,b); end;
100     end else if ch1=‘p‘ then change(a,b) else
101     if find(a)<>find(b) then writeln(‘impossible‘)else writeln(qsum(a,b));
102   end;
103 end.