#include<bits/stdc++.h>
using namespace std;
#define ll int
vector<ll>v[200005];
ll dp[200005][21];
ll lv,tmr;
ll lazy[800005],dep[200005],in[200005],out[200005];
ll csf,cc;
ll seg[800005];
void build(ll si,ll st,ll en)
{
if(st==en)
{
seg[si]=1;
return;
}
ll mi=(st+en)/2;
build(2*si+1,st,mi);
build(2*si+2,mi+1,en);
seg[si]=1;
}
void upd(ll si,ll st,ll en,ll l,ll r,ll v)
{
if(lazy[si])
{
seg[si]=lazy[si];
if(st!=en)
{
lazy[2*si+1]=lazy[2*si+2]=lazy[si];
}
lazy[si]=0;
}
if(st>r || en<l) return;
if(l<=st && r>=en)
{
seg[si]=v;
if(st!=en)
{
lazy[2*si+1]=lazy[2*si+2]=v;
}
return;
}
ll mi=(st+en)/2;
upd(2*si+1,st,mi,l,r,v);
upd(2*si+2,mi+1,en,l,r,v);
}
ll go(ll si,ll st,ll en,ll id)
{
if(lazy[si])
{
seg[si]=lazy[si];
if(st!=en)
{
lazy[2*si+1]=lazy[2*si+2]=lazy[si];
}
lazy[si]=0;
}
if(st==en) { return seg[si];}
ll mi=(st+en)/2;
if(id<=mi) return go(2*si+1,st,mi,id);
else return go(2*si+2,mi+1,en,id);
}
void dfs(ll s,ll pa,ll d)
{
dep[s]=d;
dp[s][0]=pa;
tmr+=1;
in[s]=tmr;
for(ll i=1;i<=lv;i++)
{
dp[s][i]=dp[dp[s][i-1]][i-1];
}
for(auto i:v[s])
{
if(i!=pa) dfs(i,s,d+1);
}
out[s]=tmr;
}
ll lca(ll p,ll q)
{
if(in[p]<=in[q] && out[p]>=out[q]) return p;
if(in[q]<=in[p] && out[q]>=out[p]) return q;
for(ll i=lv;i>=0;i--)
{
ll cur=dp[p][i];
if(!(in[cur]<=in[q] && out[cur]>=out[q]))
{
p=cur;
}
}
return dp[p][0];
}
int main()
{
//ios_base::sync_with_stdio(0);
//cin.tie(0);
ll i,j,k,n,m,t;
cin>>n;
csf=1;
lv=log2(n)+1;
tmr=-1;
for(i=1;i<n;i++)
{
ll p,q;
cin>>p>>q;
v[p].push_back(q);
v[q].push_back(p);
}
dfs(1,1,0);
build(0,0,tmr);
cin>>t;
while(t--)
{
char c;
ll x,y;
cin>>c>>x>>y;
ll p1=go(0,0,tmr,in[x]);
ll p2=go(0,0,tmr,in[y]);
ll p3=lca(x,y);
ll p4=go(0,0,tmr,in[p3]);
if(c=='c' || c=='d')
{
if(dp[x][0]==y) swap(x,y),swap(p1,p2);
if(dp[y][0]!=x) continue;
if(c=='c')
{
if(p1==p2) continue;
upd(0,0,tmr,in[y],out[y],p1);
}
else
{
if(p1==p2)
{
upd(0,0,tmr,in[y],out[y],csf+1);
csf+=1;
}
}
}
else
{
if(!(p1==p2 && p2==p4))
cout<<"Impossible\n";
else
{
cout<<dep[x]+dep[y]-2*dep[p3]<<"\n";
}
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBpbnQKdmVjdG9yPGxsPnZbMjAwMDA1XTsKbGwgZHBbMjAwMDA1XVsyMV07CmxsIGx2LHRtcjsKbGwgbGF6eVs4MDAwMDVdLGRlcFsyMDAwMDVdLGluWzIwMDAwNV0sb3V0WzIwMDAwNV07CmxsIGNzZixjYzsKbGwgc2VnWzgwMDAwNV07CnZvaWQgYnVpbGQobGwgc2ksbGwgc3QsbGwgZW4pCnsKICAgIGlmKHN0PT1lbikKICAgIHsKICAgICAgICBzZWdbc2ldPTE7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgbGwgbWk9KHN0K2VuKS8yOwogICAgYnVpbGQoMipzaSsxLHN0LG1pKTsKICAgIGJ1aWxkKDIqc2krMixtaSsxLGVuKTsKICAgIHNlZ1tzaV09MTsKfQp2b2lkIHVwZChsbCBzaSxsbCBzdCxsbCBlbixsbCBsLGxsIHIsbGwgdikKewogICAgaWYobGF6eVtzaV0pCiAgICB7CiAgICAgICAgc2VnW3NpXT1sYXp5W3NpXTsKICAgICAgICBpZihzdCE9ZW4pCiAgICAgICAgewogICAgICAgICAgICBsYXp5WzIqc2krMV09bGF6eVsyKnNpKzJdPWxhenlbc2ldOwogICAgICAgIH0KICAgICAgICBsYXp5W3NpXT0wOwogICAgfQogICAgaWYoc3Q+ciB8fCBlbjxsKSByZXR1cm47CiAgICBpZihsPD1zdCAmJiByPj1lbikKICAgIHsKICAgICAgICBzZWdbc2ldPXY7CiAgICAgICAgaWYoc3QhPWVuKQogICAgICAgIHsKICAgICAgICAgICAgbGF6eVsyKnNpKzFdPWxhenlbMipzaSsyXT12OwogICAgICAgIH0KICAgICAgICByZXR1cm47CiAgICB9CiAgICBsbCBtaT0oc3QrZW4pLzI7CiAgICB1cGQoMipzaSsxLHN0LG1pLGwscix2KTsKICAgIHVwZCgyKnNpKzIsbWkrMSxlbixsLHIsdik7Cn0KbGwgZ28obGwgc2ksbGwgc3QsbGwgZW4sbGwgaWQpCnsKICAgIGlmKGxhenlbc2ldKQogICAgewogICAgICAgIHNlZ1tzaV09bGF6eVtzaV07CiAgICAgICAgaWYoc3QhPWVuKQogICAgICAgIHsKICAgICAgICAgICAgbGF6eVsyKnNpKzFdPWxhenlbMipzaSsyXT1sYXp5W3NpXTsKICAgICAgICB9CiAgICAgICAgbGF6eVtzaV09MDsKICAgIH0KICAgIGlmKHN0PT1lbikgeyByZXR1cm4gc2VnW3NpXTt9CiAgICBsbCBtaT0oc3QrZW4pLzI7CiAgICBpZihpZDw9bWkpIHJldHVybiBnbygyKnNpKzEsc3QsbWksaWQpOwogICAgZWxzZSAgcmV0dXJuIGdvKDIqc2krMixtaSsxLGVuLGlkKTsKfQp2b2lkIGRmcyhsbCBzLGxsIHBhLGxsIGQpCnsKICBkZXBbc109ZDsKICBkcFtzXVswXT1wYTsKICB0bXIrPTE7CiAgaW5bc109dG1yOwogIGZvcihsbCBpPTE7aTw9bHY7aSsrKQogIHsKICAgICAgZHBbc11baV09ZHBbZHBbc11baS0xXV1baS0xXTsKICB9CiAgZm9yKGF1dG8gaTp2W3NdKQogIHsKICAgICAgaWYoaSE9cGEpIGRmcyhpLHMsZCsxKTsKICB9CiAgb3V0W3NdPXRtcjsKfQpsbCBsY2EobGwgcCxsbCBxKQp7CiAgIGlmKGluW3BdPD1pbltxXSAmJiBvdXRbcF0+PW91dFtxXSkgcmV0dXJuIHA7CiAgIGlmKGluW3FdPD1pbltwXSAmJiBvdXRbcV0+PW91dFtwXSkgcmV0dXJuIHE7CiAgIGZvcihsbCBpPWx2O2k+PTA7aS0tKQogICB7CiAgICAgICBsbCBjdXI9ZHBbcF1baV07CiAgICAgICBpZighKGluW2N1cl08PWluW3FdICYmIG91dFtjdXJdPj1vdXRbcV0pKQogICAgICAgewogICAgICAgICAgIHA9Y3VyOwogICAgICAgfQogICB9CiAgIHJldHVybiBkcFtwXVswXTsKfQoKaW50IG1haW4oKQp7CiAgICAvL2lvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICAvL2Npbi50aWUoMCk7CiAgICBsbCBpLGosayxuLG0sdDsKICAgIGNpbj4+bjsKICAgIGNzZj0xOwogICAgbHY9bG9nMihuKSsxOwogICAgdG1yPS0xOwogICAgZm9yKGk9MTtpPG47aSsrKQogICAgewogICAgICAgIGxsIHAscTsKICAgICAgICBjaW4+PnA+PnE7CiAgICAgICAgdltwXS5wdXNoX2JhY2socSk7CiAgICAgICAgdltxXS5wdXNoX2JhY2socCk7CiAgICB9CiAgICBkZnMoMSwxLDApOwogICAgYnVpbGQoMCwwLHRtcik7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pCiAgICB7CiAgICAgICAgY2hhciBjOwogICAgICAgIGxsIHgseTsKICAgICAgICBjaW4+PmM+Png+Pnk7CiAgICAgICAgbGwgcDE9Z28oMCwwLHRtcixpblt4XSk7CiAgICAgICAgbGwgcDI9Z28oMCwwLHRtcixpblt5XSk7CiAgICAgICAgbGwgcDM9bGNhKHgseSk7CiAgICAgICAgbGwgcDQ9Z28oMCwwLHRtcixpbltwM10pOwogICAgICAgIGlmKGM9PSdjJyB8fCBjPT0nZCcpCiAgICAgICAgewogICAgICAgICAgIGlmKGRwW3hdWzBdPT15KSBzd2FwKHgseSksc3dhcChwMSxwMik7CiAgICAgICAgICAgaWYoZHBbeV1bMF0hPXgpIGNvbnRpbnVlOwogICAgICAgICAgIGlmKGM9PSdjJykKICAgICAgICAgICB7CiAgICAgICAgICAgICAgIGlmKHAxPT1wMikgY29udGludWU7CgogICAgICAgICAgICAgICB1cGQoMCwwLHRtcixpblt5XSxvdXRbeV0scDEpOwogICAgICAgICAgIH0KICAgICAgICAgICBlbHNlCiAgICAgICAgICAgewogICAgICAgICAgICAgICBpZihwMT09cDIpCiAgICAgICAgICAgICAgIHsKCiAgICAgICAgICAgICAgICAgICB1cGQoMCwwLHRtcixpblt5XSxvdXRbeV0sY3NmKzEpOwogICAgICAgICAgICAgICAgICAgY3NmKz0xOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZighKHAxPT1wMiAmJiBwMj09cDQpKQogICAgICAgICAgICAgICAgY291dDw8IkltcG9zc2libGVcbiI7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgIGNvdXQ8PGRlcFt4XStkZXBbeV0tMipkZXBbcDNdPDwiXG4iOwogICAgICAgICAgICB9CgogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9Cg==