#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz 10100
int n;
vector<int> adj[sz+5],vden1[sz+5],vden2[sz+5],costn[sz+5];
int anc[sz+5][15];
int parent[sz+5],subtree[sz+5];
int mainarr[sz+5];
int vchain[sz+5],povinc[sz+5];
int headofchain[sz+5];
int level[sz+5];
int tree[6*sz +5];
int m=0,chaino=0,den=0;
int z=0;
void build(int node,int s,int e) {
z++;
if(s==e) {
tree[node]=mainarr[s];
}
else {
int mid=(s+e)/2;
build(2*node,s,mid);
build(2*node +1,mid+1,e);
tree[node]= tree[2*node]>tree[2*node +1] ? tree[2*node] : tree[2*node +1];
}
}
void update(int node,int s,int e,int idx,int val) {
z++;
if(s==e) {
tree[node]=val;
mainarr[idx]=val;
}
else {
int mid=(s+e)/2;
if(s<=idx && idx<=mid) {
update(2*node,s,mid,idx,val);
}
else {
update(2*node +1,mid+1,e,idx,val);
}
tree[node]= tree[2*node]>tree[2*node +1] ? tree[2*node] : tree[2*node +1];
}
}
int query(int node,int s,int e,int l,int r) {
z++;
if(r<s || e<l) return -1;
if(s>=l && e<=r) return tree[node];
int mid=(s+e)/2;
int p1=query(2*node,s,mid,l,r);
int p2=query(2*node +1,mid+1,e,l,r);
return p1>p2 ? p1 : p2;
}
void dfs1(int cur,int prev) {
z++;
int i,j,k;
anc[cur][0]=prev;
subtree[cur]=1;
parent[cur]=prev;
for(i=0;i<adj[cur].size();i++) {
z++;
if(adj[cur][i]!=prev) {
level[adj[cur][i]]=level[cur] +1;
dfs1(adj[cur][i],cur);
subtree[cur]+=subtree[adj[cur][i]];
}
}
}
void hld1(int cur,int prev,int cost) {
z++;
int i,j;
if(den==0) {
headofchain[chaino]=cur;
den=1;
}
vchain[cur]=chaino;
povinc[cur]=m;
mainarr[m++]=cost;
int mss=-1,vtx,ec;
for(i=0;i<adj[cur].size();i++) {
z++;
if(adj[cur][i]!=prev) {
if(subtree[adj[cur][i]]>mss || mss==-1) {
mss=subtree[adj[cur][i]];
vtx=adj[cur][i];
ec=costn[cur][i];
}
}
}
if(mss!=-1) hld1(vtx,cur,ec);
for(i=0;i<adj[cur].size();i++) {
z++;
if(adj[cur][i]!=prev && adj[cur][i]!=vtx) {
den=0;
chaino++;
hld1(adj[cur][i],cur,costn[cur][i]);
}
}
}
void precompute() {
int i,j;
for(i=1;i<=n;i++) {
for(j=1;j<14;j++) {
if(anc[i][j-1]!=-1) {
z++;
anc[i][j]=anc[anc[i][j-1]][j-1];
}
}
}
}
int lca(int x,int y) {
z++;
int i,j,k,lg;
if(level[y]>level[x]) {
int swap=x;
x=y;
y=swap;
}
int diff=level[x]-level[y];
for(int i=0;i<14;i++) if((diff>>i)&1) x=anc[x][i];
if(x==y) return x;
for(i=13;i>=0;i--) {
z++;
if(anc[x][i]!=-1 && anc[x][i]!=anc[y][i]) {
x=anc[x][i];
y=anc[y][i];
//return parent[x];
}
}
return parent[x];
}
int querybreak(int u,int v) {
z++;
//if(level[v]>level[u]) swap(u,v); // level of u will always be greater than v
int uchain=vchain[u];
int vchaino=vchain[v];
int ans=0,val,mne,mxe;
while(1) {
if(u==v) break;
z++;
uchain=vchain[u];
//cout<<"uchain="<<uchain<<" "<<vchaino<<"\n";
if(uchain==vchaino) { // u at higher level and v at lower level
// if(level[v]>level[u]) {
// int swap=u;
// u=v;
// v=swap;
// }
if(povinc[v]+1 > povinc[u])
{
mne=povinc[u];
mxe=povinc[v]+1;
}
else
{
mxe=povinc[u];
mne=povinc[v]+1;
}
//cout<<"mne="<<mne<<" mxe="<<mxe<<"\n";
val=query(1,1,m,mne,mxe);
if(val > ans)
ans=val;
break;
}
//cout<<povinc[u]<<" "<<headofchain[uchain]<<" "<<povinc[headofchain[uchain]]<<"\n";
if(povinc[u] > povinc[headofchain[uchain]])
{
mne=povinc[headofchain[uchain]];
mxe=povinc[u];
}
else
{
mxe=povinc[headofchain[uchain]];
mne=povinc[u];
}
val=query(1,1,m,mne,mxe);
//ans=maxi(ans,val);
if(val > ans)
ans=val;
u=headofchain[uchain];
u=parent[u];
}
return ans;
}
int _querybreak(int u,int v) {
z++;
int la=lca(u,v);
// if(level[v]>level[u]) {
// int swap=u;
// u=v;
// v=swap;
// }
// cout<<"u="<<u<<" v="<<v<<"\n";
// cout<<"lca="<<la<<"\n";
int v1=querybreak(u,la);
//cout<<"\n";
int v2=querybreak(v,la);
//cout<<"v1="<<v1<<" v2="<<v2<<"\n";
//return maxi(v1,v2);
return v1>v2 ? v1 : v2;
}
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int i,j,k;
int t;
scanf("%d",&t);
clock_t start=clock();
while(t--) {
scanf("%d",&n);
chaino=0;m=0;den=0;
for(i=0;i<=n;i++) {
z++;
adj[i].clear();
costn[i].clear();
vden1[i].clear();
vden2[i].clear();
headofchain[i]=-1;
for(j=1;j<=14;j++) {
anc[i][j]=-1;
}
}
int u,v,ec;
for(i=1;i<=(n-1);i++) {
z++;
scanf("%d %d %d\n",&u,&v,&ec);
adj[u].pb(v);
adj[v].pb(u);
costn[u].pb(ec);
costn[v].pb(ec);
vden1[i].pb(u);
vden2[i].pb(v);
}
level[1]=0;
dfs1(1,0);
hld1(1,0,0);
precompute();
m=m-1;
build(1,1,m);
int x,y;
// cout<<"mainarray"<<endl;
//for(int i=1;i<=n;i++)
// {cout<<mainarr[i]<<" ";
// }
// cout<<endl;
while(1) {
z++;
char s[10];
scanf("%s",s);
if(s[0]=='D') break;
if(s[0]=='Q') {
scanf("%d %d",&x,&y);
printf("%d\n",_querybreak(x,y));
}
else {
scanf("%d %d",&x,&y);
//cout<<"x="<<x<<" y="<<y<<"\n";
int fn=vden1[x][0],sn=vden2[x][0];
//cout<<fn<<" "<<sn<<"\n";
if(level[sn]>level[fn]) {
int swap=fn;
fn=sn;
sn=swap;
}
//cout<<povinc[fn]<<"\n";
update(1,1,m,povinc[fn],y);
//cout<<tree[2]<<"\n";
}
}
}
//cout<<"total_itern="<<z<<"\n";
//double dur=(clock()- start)*1.0/(CLOCKS_PER_SEC);
//cout<<fixed<<dur<<"\n";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgICAgZiAgICAgICAgICAgICAgIGZpcnN0CiNkZWZpbmUgICAgcyAgICAgICAgICAgICAgIHNlY29uZAojZGVmaW5lICAgIHBiICAgICAgICAgICAgICBwdXNoX2JhY2sKI2RlZmluZSAgICBtcCAgICAgICAgICAgICAgbWFrZV9wYWlyCiNkZWZpbmUgICAgc3ogICAgICAgICAgICAgIDEwMTAwCgppbnQgbjsKdmVjdG9yPGludD4gYWRqW3N6KzVdLHZkZW4xW3N6KzVdLHZkZW4yW3N6KzVdLGNvc3RuW3N6KzVdOwppbnQgYW5jW3N6KzVdWzE1XTsKaW50IHBhcmVudFtzeis1XSxzdWJ0cmVlW3N6KzVdOwppbnQgbWFpbmFycltzeis1XTsKaW50IHZjaGFpbltzeis1XSxwb3ZpbmNbc3orNV07CmludCBoZWFkb2ZjaGFpbltzeis1XTsKaW50IGxldmVsW3N6KzVdOwppbnQgdHJlZVs2KnN6ICs1XTsKCmludCBtPTAsY2hhaW5vPTAsZGVuPTA7CmludCB6PTA7CnZvaWQgYnVpbGQoaW50IG5vZGUsaW50IHMsaW50IGUpIHsKICAgIHorKzsKICAgIGlmKHM9PWUpIHsKICAgICAgICB0cmVlW25vZGVdPW1haW5hcnJbc107CiAgICB9CiAgICBlbHNlIHsKICAgICAgICAKICAgICAgICBpbnQgbWlkPShzK2UpLzI7CiAgICAgICAgYnVpbGQoMipub2RlLHMsbWlkKTsKICAgICAgICBidWlsZCgyKm5vZGUgKzEsbWlkKzEsZSk7CiAgICAgICAgdHJlZVtub2RlXT0gdHJlZVsyKm5vZGVdPnRyZWVbMipub2RlICsxXSA/IHRyZWVbMipub2RlXSA6IHRyZWVbMipub2RlICsxXTsKICAgIH0KfQoKdm9pZCB1cGRhdGUoaW50IG5vZGUsaW50IHMsaW50IGUsaW50IGlkeCxpbnQgdmFsKSB7CiAgICB6Kys7CiAgICBpZihzPT1lKSB7CiAgICAgICAgdHJlZVtub2RlXT12YWw7CiAgICAgICAgbWFpbmFycltpZHhdPXZhbDsKICAgIH0KICAgIGVsc2UgewogICAgICAgIAogICAgICAgIGludCBtaWQ9KHMrZSkvMjsKICAgICAgICAKICAgICAgICBpZihzPD1pZHggJiYgaWR4PD1taWQpIHsKICAgICAgICAgICAgdXBkYXRlKDIqbm9kZSxzLG1pZCxpZHgsdmFsKTsKICAgICAgICB9CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIHVwZGF0ZSgyKm5vZGUgKzEsbWlkKzEsZSxpZHgsdmFsKTsKICAgICAgICB9CiAgICAgICAgdHJlZVtub2RlXT0gdHJlZVsyKm5vZGVdPnRyZWVbMipub2RlICsxXSA/IHRyZWVbMipub2RlXSA6IHRyZWVbMipub2RlICsxXTsKICAgIH0KfQoKaW50IHF1ZXJ5KGludCBub2RlLGludCBzLGludCBlLGludCBsLGludCByKSB7CiAgICB6Kys7CiAgICBpZihyPHMgfHwgZTxsKSByZXR1cm4gLTE7CiAgICAKICAgIGlmKHM+PWwgICYmIGU8PXIpIHJldHVybiB0cmVlW25vZGVdOwogICAgCiAgICBpbnQgbWlkPShzK2UpLzI7CiAgICAKICAgIGludCBwMT1xdWVyeSgyKm5vZGUscyxtaWQsbCxyKTsKICAgIGludCBwMj1xdWVyeSgyKm5vZGUgKzEsbWlkKzEsZSxsLHIpOwogICAgCiAgICByZXR1cm4gcDE+cDIgPyBwMSA6IHAyOwp9CgoKdm9pZCBkZnMxKGludCBjdXIsaW50IHByZXYpIHsKICAgIHorKzsKICAgIGludCBpLGosazsKICAgIGFuY1tjdXJdWzBdPXByZXY7CiAgICBzdWJ0cmVlW2N1cl09MTsKICAgIHBhcmVudFtjdXJdPXByZXY7CiAgICAKICAgIGZvcihpPTA7aTxhZGpbY3VyXS5zaXplKCk7aSsrKSB7CiAgICAgICAgeisrOwogICAgICAgIGlmKGFkaltjdXJdW2ldIT1wcmV2KSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBsZXZlbFthZGpbY3VyXVtpXV09bGV2ZWxbY3VyXSArMTsKICAgICAgICAgICAgZGZzMShhZGpbY3VyXVtpXSxjdXIpOwogICAgICAgICAgICAKICAgICAgICAgICAgc3VidHJlZVtjdXJdKz1zdWJ0cmVlW2FkaltjdXJdW2ldXTsKICAgICAgICB9CiAgICB9Cn0KCnZvaWQgaGxkMShpbnQgY3VyLGludCBwcmV2LGludCBjb3N0KSB7CiAgICB6Kys7CiAgICBpbnQgaSxqOwogICAgCiAgICBpZihkZW49PTApIHsKICAgICAgICBoZWFkb2ZjaGFpbltjaGFpbm9dPWN1cjsKICAgICAgICBkZW49MTsKICAgIH0KICAgIHZjaGFpbltjdXJdPWNoYWlubzsKICAgIHBvdmluY1tjdXJdPW07CiAgICBtYWluYXJyW20rK109Y29zdDsKICAgIAogICAgaW50IG1zcz0tMSx2dHgsZWM7CiAgICAKICAgIGZvcihpPTA7aTxhZGpbY3VyXS5zaXplKCk7aSsrKSB7CiAgICAgICAgeisrOwogICAgICAgIGlmKGFkaltjdXJdW2ldIT1wcmV2KSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBpZihzdWJ0cmVlW2FkaltjdXJdW2ldXT5tc3MgfHwgbXNzPT0tMSkgewogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBtc3M9c3VidHJlZVthZGpbY3VyXVtpXV07CiAgICAgICAgICAgICAgICB2dHg9YWRqW2N1cl1baV07CiAgICAgICAgICAgICAgICBlYz1jb3N0bltjdXJdW2ldOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgCiAgICBpZihtc3MhPS0xKSBobGQxKHZ0eCxjdXIsZWMpOwogICAgCiAgICBmb3IoaT0wO2k8YWRqW2N1cl0uc2l6ZSgpO2krKykgewogICAgICAgIHorKzsKICAgICAgICBpZihhZGpbY3VyXVtpXSE9cHJldiAmJiBhZGpbY3VyXVtpXSE9dnR4KSB7CiAgICAgICAgICAgIGRlbj0wOwogICAgICAgICAgICBjaGFpbm8rKzsKICAgICAgICAgICAgaGxkMShhZGpbY3VyXVtpXSxjdXIsY29zdG5bY3VyXVtpXSk7CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIHByZWNvbXB1dGUoKSB7CiAgICAKICAgIGludCBpLGo7CiAgICBmb3IoaT0xO2k8PW47aSsrKSB7CiAgICAgICAgZm9yKGo9MTtqPDE0O2orKykgewogICAgICAgICAgICBpZihhbmNbaV1bai0xXSE9LTEpIHsKICAgICAgICAgICAgICAgIHorKzsKICAgICAgICAgICAgICAgIGFuY1tpXVtqXT1hbmNbYW5jW2ldW2otMV1dW2otMV07CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCmludCBsY2EoaW50IHgsaW50IHkpIHsKICAgIHorKzsKICAgIGludCBpLGosayxsZzsKICAgIGlmKGxldmVsW3ldPmxldmVsW3hdKSB7CiAgICAgICAgaW50IHN3YXA9eDsKICAgICAgICB4PXk7CiAgICAgICAgeT1zd2FwOwogICAgfQogICAgCiAgICBpbnQgZGlmZj1sZXZlbFt4XS1sZXZlbFt5XTsKICAgIGZvcihpbnQgaT0wO2k8MTQ7aSsrKSBpZigoZGlmZj4+aSkmMSkgeD1hbmNbeF1baV07CiAgICBpZih4PT15KSByZXR1cm4geDsKICAgIAogICAgZm9yKGk9MTM7aT49MDtpLS0pIHsKICAgICAgICB6Kys7CiAgICAgICAgaWYoYW5jW3hdW2ldIT0tMSAmJiBhbmNbeF1baV0hPWFuY1t5XVtpXSkgewogICAgICAgICAgICB4PWFuY1t4XVtpXTsKICAgICAgICAgICAgeT1hbmNbeV1baV07CiAgICAgICAgICAgIC8vcmV0dXJuIHBhcmVudFt4XTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gcGFyZW50W3hdOwp9CgppbnQgcXVlcnlicmVhayhpbnQgdSxpbnQgdikgewogICAgCiAgICB6Kys7CiAgICAvL2lmKGxldmVsW3ZdPmxldmVsW3VdKSBzd2FwKHUsdik7IC8vIGxldmVsIG9mIHUgd2lsbCBhbHdheXMgYmUgZ3JlYXRlciB0aGFuIHYKICAgIAogICAgaW50IHVjaGFpbj12Y2hhaW5bdV07CiAgICBpbnQgdmNoYWlubz12Y2hhaW5bdl07CiAgICBpbnQgYW5zPTAsdmFsLG1uZSxteGU7CiAgICB3aGlsZSgxKSB7CiAgICAgICAgCiAgICAgICAgaWYodT09dikgYnJlYWs7CiAgICAgICAgeisrOwogICAgICAgIHVjaGFpbj12Y2hhaW5bdV07CiAgICAgICAgLy9jb3V0PDwidWNoYWluPSI8PHVjaGFpbjw8IiAiPDx2Y2hhaW5vPDwiXG4iOwogICAgICAgIGlmKHVjaGFpbj09dmNoYWlubykgeyAgLy8gdSBhdCBoaWdoZXIgbGV2ZWwgYW5kIHYgYXQgbG93ZXIgbGV2ZWwKICAgICAgICAgICAgIAogICAgICAgICAgICAvLyAgaWYobGV2ZWxbdl0+bGV2ZWxbdV0pIHsKICAgICAgICAgICAgLy8gICAgICBpbnQgc3dhcD11OwogICAgICAgICAgICAvLyAgICAgIHU9djsKICAgICAgICAgICAgLy8gICAgICB2PXN3YXA7CiAgICAgICAgICAgIC8vICB9CiAgICAgICAgICAgICBpZihwb3ZpbmNbdl0rMSA+IHBvdmluY1t1XSkKICAgICAgICAgICAgIHsKICAgICAgICAgICAgIAltbmU9cG92aW5jW3VdOwogICAgICAgICAgICAgCW14ZT1wb3ZpbmNbdl0rMTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgIHsKICAgICAgICAgICAgIAlteGU9cG92aW5jW3VdOwogICAgICAgICAgICAgCW1uZT1wb3ZpbmNbdl0rMTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgIC8vY291dDw8Im1uZT0iPDxtbmU8PCIgbXhlPSI8PG14ZTw8IlxuIjsKICAgICAgICAgICAgIHZhbD1xdWVyeSgxLDEsbSxtbmUsbXhlKTsKICAgICAgICAgICAgIGlmKHZhbCA+IGFucykKICAgICAgICAgICAgIGFucz12YWw7CiAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy9jb3V0PDxwb3ZpbmNbdV08PCIgIjw8aGVhZG9mY2hhaW5bdWNoYWluXTw8IiAiPDxwb3ZpbmNbaGVhZG9mY2hhaW5bdWNoYWluXV08PCJcbiI7CiAgICAgICAgaWYocG92aW5jW3VdID4gcG92aW5jW2hlYWRvZmNoYWluW3VjaGFpbl1dKQogICAgICAgIHsKICAgICAgICAJbW5lPXBvdmluY1toZWFkb2ZjaGFpblt1Y2hhaW5dXTsKICAgICAgICAgICAgbXhlPXBvdmluY1t1XTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAJbXhlPXBvdmluY1toZWFkb2ZjaGFpblt1Y2hhaW5dXTsKICAgICAgICAgICAgbW5lPXBvdmluY1t1XTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgdmFsPXF1ZXJ5KDEsMSxtLG1uZSxteGUpOwogICAgICAgIC8vYW5zPW1heGkoYW5zLHZhbCk7CiAgICAgICAgaWYodmFsID4gYW5zKQogICAgICAgIGFucz12YWw7CiAgICAgICAgdT1oZWFkb2ZjaGFpblt1Y2hhaW5dOwogICAgICAgIHU9cGFyZW50W3VdOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKaW50IF9xdWVyeWJyZWFrKGludCB1LGludCB2KSB7CiAgICAKICAgIHorKzsKICAgIGludCBsYT1sY2EodSx2KTsKICAgIC8vIGlmKGxldmVsW3ZdPmxldmVsW3VdKSB7CiAgICAvLyAgICAgaW50IHN3YXA9dTsKICAgIC8vICAgICB1PXY7CiAgICAvLyAgICAgdj1zd2FwOwogICAgLy8gfQogICAgCiAgICAvLyBjb3V0PDwidT0iPDx1PDwiIHY9Ijw8djw8IlxuIjsKICAgIC8vIGNvdXQ8PCJsY2E9Ijw8bGE8PCJcbiI7CiAgICAKICAgIGludCB2MT1xdWVyeWJyZWFrKHUsbGEpOwogICAgLy9jb3V0PDwiXG4iOwogICAgaW50IHYyPXF1ZXJ5YnJlYWsodixsYSk7CiAgICAKICAgIC8vY291dDw8InYxPSI8PHYxPDwiIHYyPSI8PHYyPDwiXG4iOwogICAgLy9yZXR1cm4gbWF4aSh2MSx2Mik7CiAgICByZXR1cm4gdjE+djIgPyB2MSA6IHYyOwp9CgppbnQgbWFpbigpIHsKICAgIAogICAgLy8gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIC8vIGNpbi50aWUoMCk7CiAgICAvLyBjb3V0LnRpZSgwKTsKICAgIAogICAgaW50IGksaixrOwogICAgCiAgICBpbnQgdDsKICAgIHNjYW5mKCIlZCIsJnQpOwogICAgCiAgICBjbG9ja190IHN0YXJ0PWNsb2NrKCk7CiAgICB3aGlsZSh0LS0pIHsKICAgICAgICAKICAgICAgICBzY2FuZigiJWQiLCZuKTsKICAgICAgICAKICAgICAgICBjaGFpbm89MDttPTA7ZGVuPTA7CiAgICAgICAgZm9yKGk9MDtpPD1uO2krKykgewogICAgICAgICAgICB6Kys7CiAgICAgICAgICAgIGFkaltpXS5jbGVhcigpOwogICAgICAgICAgICBjb3N0bltpXS5jbGVhcigpOwogICAgICAgICAgICB2ZGVuMVtpXS5jbGVhcigpOwogICAgICAgICAgICB2ZGVuMltpXS5jbGVhcigpOwogICAgICAgICAgICBoZWFkb2ZjaGFpbltpXT0tMTsKICAgICAgICAgICAgZm9yKGo9MTtqPD0xNDtqKyspIHsKICAgICAgICAgICAgICAgIGFuY1tpXVtqXT0tMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgdSx2LGVjOwogICAgICAgIAogICAgICAgIGZvcihpPTE7aTw9KG4tMSk7aSsrKSB7CiAgICAgICAgICAgIHorKzsKICAgICAgICAgICAgc2NhbmYoIiVkICVkICVkXG4iLCZ1LCZ2LCZlYyk7CiAgICAgICAgICAgIGFkalt1XS5wYih2KTsKICAgICAgICAgICAgYWRqW3ZdLnBiKHUpOwogICAgICAgICAgICBjb3N0blt1XS5wYihlYyk7CiAgICAgICAgICAgIGNvc3RuW3ZdLnBiKGVjKTsKICAgICAgICAgICAgdmRlbjFbaV0ucGIodSk7CiAgICAgICAgICAgIHZkZW4yW2ldLnBiKHYpOwogICAgICAgIH0KICAgICAgICBsZXZlbFsxXT0wOwogICAgICAgIGRmczEoMSwwKTsKICAgICAgICBobGQxKDEsMCwwKTsKICAgICAgICBwcmVjb21wdXRlKCk7CiAgICAgICAgbT1tLTE7CiAgICAgICAgYnVpbGQoMSwxLG0pOwogICAgICAgIAogICAgICAgIGludCB4LHk7CiAgICAgICAvLyBjb3V0PDwibWFpbmFycmF5Ijw8ZW5kbDsKICAgICAgICAvL2ZvcihpbnQgaT0xO2k8PW47aSsrKQogICAgICAgLy8ge2NvdXQ8PG1haW5hcnJbaV08PCIgIjsKICAgICAgIC8vIH0KICAgICAgIC8vIGNvdXQ8PGVuZGw7CiAgICAgICAgd2hpbGUoMSkgewogICAgICAgICAgICB6Kys7CiAgICAgICAgICAgIGNoYXIgc1sxMF07CiAgICAgICAgICAgIHNjYW5mKCIlcyIscyk7CiAgICAgICAgICAgIGlmKHNbMF09PSdEJykgYnJlYWs7CiAgICAgICAgICAgIAogICAgICAgICAgICBpZihzWzBdPT0nUScpIHsKICAgICAgICAgICAgICAgc2NhbmYoIiVkICVkIiwmeCwmeSk7CiAgICAgICAgICAgICAgIHByaW50ZigiJWRcbiIsX3F1ZXJ5YnJlYWsoeCx5KSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICBzY2FuZigiJWQgJWQiLCZ4LCZ5KTsKICAgICAgICAgICAgICAgIC8vY291dDw8Ing9Ijw8eDw8IiB5PSI8PHk8PCJcbiI7CiAgICAgICAgICAgICAgICBpbnQgZm49dmRlbjFbeF1bMF0sc249dmRlbjJbeF1bMF07CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIC8vY291dDw8Zm48PCIgIjw8c248PCJcbiI7CiAgICAgICAgICAgICAgICBpZihsZXZlbFtzbl0+bGV2ZWxbZm5dKSB7CiAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgaW50IHN3YXA9Zm47CiAgICAgICAgICAgICAgICAgICAgZm49c247CiAgICAgICAgICAgICAgICAgICAgc249c3dhcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIC8vY291dDw8cG92aW5jW2ZuXTw8IlxuIjsKICAgICAgICAgICAgICAgIHVwZGF0ZSgxLDEsbSxwb3ZpbmNbZm5dLHkpOwogICAgICAgICAgICAgICAgLy9jb3V0PDx0cmVlWzJdPDwiXG4iOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgLy9jb3V0PDwidG90YWxfaXRlcm49Ijw8ejw8IlxuIjsKICAgIC8vZG91YmxlIGR1cj0oY2xvY2soKS0gc3RhcnQpKjEuMC8oQ0xPQ0tTX1BFUl9TRUMpOwogICAgLy9jb3V0PDxmaXhlZDw8ZHVyPDwiXG4iOwogICAgcmV0dXJuIDA7Cn0=