#include <bits/stdc++.h>   const int fin = 0, maxn = 400000, maxm = maxn << 1;   int n, m, cent, tot;   int fs[maxn], e[maxm], next[maxm];   int bel[maxn], pos[maxn], len[maxn], left[maxn];   int c[maxn], deg[maxn], b[maxn];   bool v[maxn];   struct rec {     int x, y;   } g[maxn];   int sum(int *a, int n, int x) {     int s = 0;     for (; x; x -= ((x) & (-(x)))) s += a[x];     return s;   }   void upd(int *a, int n, int x, int w) {     for (; x <= n; x += ((x) & (-(x)))) a[x] += w;   }   inline void addedge(int x, int y) {     e[++m] = y;     next[m] = fs[x];     fs[x] = m;     e[++m] = x;     next[m] = fs[y];     fs[y] = m;   }   void init() {     int i;     scanf( %d , &n);     m = 0;     for (i = 1; i < n; ++i) {       scanf( %d%d , &g[i].x, &g[i].y);       addedge(g[i].x, g[i].y);       deg[g[i].x]++;       deg[g[i].y]++;     }     cent = 0;     for (i = 1; i <= n; ++i)       if (deg[i] > 2) {         cent = i;         break;       }     if (!cent) cent = 1;   }   void build() {     int i, j, p, k, t;     i = fs[cent];     tot = 0;     v[cent] = true;     bel[cent] = 0;     for (j = 1; j <= deg[cent]; ++j) {       p = e[i];       bel[p] = j;       v[p] = true;       b[++tot] = p;       pos[p] = 1;       left[j] = tot;       while (next[fs[p]]) {         if (v[e[fs[p]]])           t = e[next[fs[p]]];         else           t = e[fs[p]];         v[t] = true;         b[++tot] = t;         bel[t] = j;         pos[t] = pos[p] + 1;         p = t;       }       len[j] = tot - left[j] + 1;       i = next[i];       for (k = 1; k <= len[j]; ++k) upd(c + left[j] - 1, len[j], k, 1);     }   }   void solve() {     int que, x, y, j, t, type, p, k;     scanf( %d , &que);     while (que--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d , &p);         x = g[p].x;         y = g[p].y;         if ((!bel[x]) || (!bel[y])) {           j = bel[y] + bel[x];           upd(c + left[j] - 1, len[j], 1, 1);         } else {           j = bel[x];           if (pos[x] > pos[y])             k = pos[x];           else             k = pos[y];           upd(c + left[j] - 1, len[j], k, 1);         }       } else if (type == 2) {         scanf( %d , &p);         x = g[p].x;         y = g[p].y;         if ((!bel[x]) || (!bel[y])) {           j = bel[y] + bel[x];           upd(c + left[j] - 1, len[j], 1, -1);         } else {           j = bel[x];           if (pos[x] > pos[y])             k = pos[x];           else             k = pos[y];           upd(c + left[j] - 1, len[j], k, -1);         }       } else {         scanf( %d%d , &x, &y);         if (x == y)           printf( 0 n );         else {           if ((!bel[x]) || (!bel[y])) {             j = bel[x] + bel[y];             if (!bel[x])               k = pos[y];             else               k = pos[x];             t = sum(c + left[j] - 1, len[j], k);             if (t == k)               printf( %d n , t);             else               printf( -1 n );           } else if (bel[x] == bel[y]) {             j = bel[x];             if (pos[x] > pos[y]) {               t = x;               x = y;               y = t;             }             t = sum(c + left[j] - 1, len[j], pos[y]) -                 sum(c + left[j] - 1, len[j], pos[x]);             if (t == pos[y] - pos[x])               printf( %d n , t);             else               printf( -1 n );           } else {             j = bel[x];             t = sum(c + left[j] - 1, len[j], pos[x]);             j = bel[y];             t += sum(c + left[j] - 1, len[j], pos[y]);             if (t == pos[x] + pos[y])               printf( %d n , t);             else               printf( -1 n );           }         }       }     }   }   int main() {     if (fin) {       freopen( t.in ,  r , stdin);       freopen( t.out ,  w , stdout);     }     init();     build();     solve();     if (fin) {       fclose(stdin);       fclose(stdout);     }     return 0;   }