#include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k, l;
const int V = 2e5 + 5;
const int E = V * 2;
int u[V];
int e[E], es[E], eb[V], ed, deg[V], ei[E];
void add_e(int v, int u, int i) {
  e[++ed] = u;
  ei[ed] = i;
  es[ed] = eb[v];
  eb[v] = ed;
  ++deg[v];
}
int root;
int *f[V], nf[V];
int w[V][2];
int we[V][2];
void upd(int f[], int n, int i, int v) {
  while (i < n) {
    f[i] += v;
    i = (i | (i + 1));
  }
}
int sum(int f[], int i) {
  int s = 0;
  while (i >= 0) {
    s += f[i];
    i = (i & (i + 1)) - 1;
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (k = 1; k < n; ++k) {
    cin >> i >> j;
    add_e(i, j, k);
    add_e(j, i, k);
  }
  root = 1;
  for (i = 1; i <= n; ++i)
    if (deg[i] > 2) root = i;
  u[root] = 2;
  w[root][0] = w[root][1] = -1;
  m = 0;
  for (k = eb[root]; k; k = es[k]) {
    i = e[k];
    for (;;) {
      u[i] = 1;
      ++nf[m];
      for (j = eb[i]; j; j = es[j])
        if (u[e[j]] == 0) {
          i = e[j];
          break;
        }
      if (u[i] == 1) break;
    }
    f[m] = new int[nf[m] + 5];
    memset(f[m], 0, (nf[m] + 5) * 4);
    for (i = 0; i < nf[m]; ++i) upd(f[m], nf[m], i, +1);
    i = e[k];
    l = 0;
    we[ei[k]][0] = m;
    we[ei[k]][1] = 0;
    for (;;) {
      u[i] = 2;
      w[i][0] = m;
      w[i][1] = l++;
      for (j = eb[i]; j; j = es[j])
        if (u[e[j]] == 1) {
          i = e[j];
          we[ei[j]][0] = m;
          we[ei[j]][1] = l;
          break;
        }
      if (u[i] == 2) break;
    }
    ++m;
  }
  int q;
  cin >> q;
  while (q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      cin >> i;
      upd(f[we[i][0]], nf[we[i][0]], we[i][1], +1);
    } else if (tp == 2) {
      cin >> i;
      upd(f[we[i][0]], nf[we[i][0]], we[i][1], -1);
    } else if (tp == 3) {
      cin >> i >> j;
      if (j == root) swap(i, j);
      int d;
      if (i == j)
        d = 0;
      else if (i == root) {
        d = sum(f[w[j][0]], w[j][1]);
        if (d != w[j][1] + 1) d = -1;
      } else if (w[i][0] != w[j][0]) {
        int d1 = sum(f[w[i][0]], w[i][1]);
        if (d1 != w[i][1] + 1) d1 = -1;
        int d2 = sum(f[w[j][0]], w[j][1]);
        if (d2 != w[j][1] + 1) d2 = -1;
        if (d1 < 0 || d2 < 0)
          d = -1;
        else
          d = d1 + d2;
      } else {
        if (w[i][1] > w[j][1]) swap(i, j);
        d = sum(f[w[j][0]], w[j][1]) - sum(f[w[i][0]], w[i][1]);
        if (d != w[j][1] - w[i][1]) d = -1;
      }
      cout << d << endl;
    }
  }
  return 0;
}
