#include <cstdio>
#include <vector>
using namespace std;
struct muchie
{
int nod,poz;
muchie(int nod1,int poz1) {nod=nod1;poz=poz1;}
};
vector<muchie> v[100010];
vector<int> aib[100010];
int niv[100010],lant1[100010],lant2[100010],poz[100010],size[100010];
char vaz[100010];
void aib_update(int nr,int i,int s)
{
for(;i<=size[nr];i+=i&(-i)) aib[nr][i]+=s;
}
int aib_query(int nr,int i)
{
int s=0;
for(;i>0;i-=i&(-i)) s+=aib[nr][i];
return s;
}
int main()
{
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
int n,nod,x,y,m,nr=0,tip,a,b;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
scanf("%d%d",&x,&y);
v[x].push_back(muchie(y,i));
v[y].push_back(muchie(x,i));
}
for(nod=1;nod<=n;nod++) if(v[nod].size()>2) break;
if(nod==n+1) nod=1;
vaz[nod]=1;
for(vector<muchie>::iterator it=v[nod].begin();it!=v[nod].end();it++)
{
lant1[it->poz]=++nr;
poz[it->poz]=1;
int x=it->nod;
for(int i=2;;i++)
{
lant2[x]=nr;
vaz[x]=1;
niv[x]=i-1;
if(!vaz[v[x][0].nod]) {poz[v[x][0].poz]=i;lant1[v[x][0].poz]=nr;x=v[x][0].nod;}
else if(v[x].size()>1) {poz[v[x][1].poz]=i;lant1[v[x][1].poz]=nr;x=v[x][1].nod;}
else
{
size[nr]=i;
aib[nr].resize(size[nr]+2);
break;
}
}
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&tip);
if(tip==1)
{
scanf("%d",&a);
aib_update(lant1[a],poz[a],-1);
}
else if(tip==2)
{
scanf("%d",&a);
aib_update(lant1[a],poz[a],1);
}
else
{
scanf("%d%d",&a,&b);
if(lant2[a]==lant2[b])
{
int x=niv[a],y=niv[b];
if(x>y) swap(x,y);
if(aib_query(lant2[a],y)-aib_query(lant2[a],x)) printf("-1\n");
else printf("%d\n",y-x);
}
else if(a==nod || b==nod)
{
if(a==nod) swap(a,b);
if(a==nod) {printf("0\n");continue;}
if(aib_query(lant2[a],niv[a])) printf("-1\n");
else printf("%d\n",niv[a]);
}
else
{
if(aib_query(lant2[a],niv[a])+aib_query(lant2[b],niv[b])) printf("-1\n");
else printf("%d\n",niv[a]+niv[b]);
}
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgbXVjaGllCnsKICAgIGludCBub2QscG96OwogICAgbXVjaGllKGludCBub2QxLGludCBwb3oxKSB7bm9kPW5vZDE7cG96PXBvejE7fQp9Owp2ZWN0b3I8bXVjaGllPiB2WzEwMDAxMF07CnZlY3RvcjxpbnQ+IGFpYlsxMDAwMTBdOwppbnQgbml2WzEwMDAxMF0sbGFudDFbMTAwMDEwXSxsYW50MlsxMDAwMTBdLHBvelsxMDAwMTBdLHNpemVbMTAwMDEwXTsKY2hhciB2YXpbMTAwMDEwXTsKCnZvaWQgYWliX3VwZGF0ZShpbnQgbnIsaW50IGksaW50IHMpCnsKICAgIGZvcig7aTw9c2l6ZVtucl07aSs9aSYoLWkpKSBhaWJbbnJdW2ldKz1zOwp9CgppbnQgYWliX3F1ZXJ5KGludCBucixpbnQgaSkKewogICAgaW50IHM9MDsKICAgIGZvcig7aT4wO2ktPWkmKC1pKSkgcys9YWliW25yXVtpXTsKICAgIHJldHVybiBzOwp9CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiZmlsZS5pbiIsICJyIiwgc3RkaW4pOwogICAgLy9mcmVvcGVuKCJmaWxlLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIGludCBuLG5vZCx4LHksbSxucj0wLHRpcCxhLGI7CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIGZvcihpbnQgaT0xO2k8bjtpKyspCiAgICB7CiAgICAgICAgc2NhbmYoIiVkJWQiLCZ4LCZ5KTsKICAgICAgICB2W3hdLnB1c2hfYmFjayhtdWNoaWUoeSxpKSk7CiAgICAgICAgdlt5XS5wdXNoX2JhY2sobXVjaGllKHgsaSkpOwogICAgfQogICAgZm9yKG5vZD0xO25vZDw9bjtub2QrKykgaWYodltub2RdLnNpemUoKT4yKSBicmVhazsKICAgIGlmKG5vZD09bisxKSBub2Q9MTsKICAgIHZheltub2RdPTE7CiAgICBmb3IodmVjdG9yPG11Y2hpZT46Oml0ZXJhdG9yIGl0PXZbbm9kXS5iZWdpbigpO2l0IT12W25vZF0uZW5kKCk7aXQrKykKICAgIHsKICAgICAgICBsYW50MVtpdC0+cG96XT0rK25yOwogICAgICAgIHBveltpdC0+cG96XT0xOwogICAgICAgIGludCB4PWl0LT5ub2Q7CiAgICAgICAgZm9yKGludCBpPTI7O2krKykKICAgICAgICB7CiAgICAgICAgICAgIGxhbnQyW3hdPW5yOwogICAgICAgICAgICB2YXpbeF09MTsKICAgICAgICAgICAgbml2W3hdPWktMTsKICAgICAgICAgICAgaWYoIXZhelt2W3hdWzBdLm5vZF0pIHtwb3pbdlt4XVswXS5wb3pdPWk7bGFudDFbdlt4XVswXS5wb3pdPW5yO3g9dlt4XVswXS5ub2Q7fQogICAgICAgICAgICBlbHNlIGlmKHZbeF0uc2l6ZSgpPjEpIHtwb3pbdlt4XVsxXS5wb3pdPWk7bGFudDFbdlt4XVsxXS5wb3pdPW5yO3g9dlt4XVsxXS5ub2Q7fQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNpemVbbnJdPWk7CiAgICAgICAgICAgICAgICBhaWJbbnJdLnJlc2l6ZShzaXplW25yXSsyKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgc2NhbmYoIiVkIiwmbSk7CiAgICBmb3IoaW50IGk9MTtpPD1tO2krKykKICAgIHsKICAgICAgICBzY2FuZigiJWQiLCZ0aXApOwogICAgICAgIGlmKHRpcD09MSkKICAgICAgICB7CiAgICAgICAgICAgIHNjYW5mKCIlZCIsJmEpOwogICAgICAgICAgICBhaWJfdXBkYXRlKGxhbnQxW2FdLHBvelthXSwtMSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYodGlwPT0yKQogICAgICAgIHsKICAgICAgICAgICAgc2NhbmYoIiVkIiwmYSk7CiAgICAgICAgICAgIGFpYl91cGRhdGUobGFudDFbYV0scG96W2FdLDEpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBzY2FuZigiJWQlZCIsJmEsJmIpOwogICAgICAgICAgICBpZihsYW50MlthXT09bGFudDJbYl0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCB4PW5pdlthXSx5PW5pdltiXTsKICAgICAgICAgICAgICAgIGlmKHg+eSkgc3dhcCh4LHkpOwogICAgICAgICAgICAgICAgaWYoYWliX3F1ZXJ5KGxhbnQyW2FdLHkpLWFpYl9xdWVyeShsYW50MlthXSx4KSkgcHJpbnRmKCItMVxuIik7CiAgICAgICAgICAgICAgICBlbHNlIHByaW50ZigiJWRcbiIseS14KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKGE9PW5vZCB8fCBiPT1ub2QpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGE9PW5vZCkgc3dhcChhLGIpOwogICAgICAgICAgICAgICAgaWYoYT09bm9kKSB7cHJpbnRmKCIwXG4iKTtjb250aW51ZTt9CiAgICAgICAgICAgICAgICBpZihhaWJfcXVlcnkobGFudDJbYV0sbml2W2FdKSkgcHJpbnRmKCItMVxuIik7CiAgICAgICAgICAgICAgICBlbHNlIHByaW50ZigiJWRcbiIsbml2W2FdKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKGFpYl9xdWVyeShsYW50MlthXSxuaXZbYV0pK2FpYl9xdWVyeShsYW50MltiXSxuaXZbYl0pKSBwcmludGYoIi0xXG4iKTsKICAgICAgICAgICAgICAgIGVsc2UgcHJpbnRmKCIlZFxuIixuaXZbYV0rbml2W2JdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9