#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int M = N << 1;
int nxt[M], to[M], eb[N], en;
int dep[N], dg[N], hd[N], pos[N];
struct BIT {
  int d[N], n;
  void init() { memset(d, 0, sizeof(d)); }
  void add(int x, int t) {
    for (int i = x; i <= n; i += i & -i) d[i] += t;
  }
  int query(int x) {
    int ans = 0;
    for (int i = x; i >= 1; i -= i & -i) ans += d[i];
    return ans;
  }
} tr;
vector<pair<int, int> > e;
int main() {
  int i, j, k, n, m, tp;
  scanf("%d", &n);
  for (memset(eb, -1, sizeof(eb)), i = 1; i < n; i++) {
    scanf("%d%d", &j, &k);
    e.push_back(make_pair(j, k));
    dg[j]++, dg[k]++;
    to[en] = k;
    nxt[en] = eb[j];
    eb[j] = en++;
    to[en] = j;
    nxt[en] = eb[k];
    eb[k] = en++;
  }
  int rt = 1;
  for (i = 1; i <= n; i++)
    if (dg[i] > 2) {
      rt = i;
      break;
    }
  int cnt = 0;
  for (int ee = eb[rt]; ee != -1; ee = nxt[ee]) {
    int head = to[ee], len = 0, last = rt;
    k = head;
    while (true) {
      pos[k] = ++cnt;
      hd[k] = head;
      dep[k] = ++len;
      if (dg[k] == 1) break;
      for (int eee = eb[k]; eee != -1; eee = nxt[eee]) {
        if ((j = to[eee]) == last) continue;
        last = k;
        k = j;
        break;
      }
    }
  }
  tr.n = n;
  tr.init();
  for (scanf("%d", &m); m; m--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d", &k);
      int x = e[k - 1].first, y = e[k - 1].second;
      if (dep[x] < dep[y]) swap(x, y);
      tr.add(pos[x], -1);
    } else if (tp == 2) {
      scanf("%d", &k);
      int x = e[k - 1].first, y = e[k - 1].second;
      if (dep[x] < dep[y]) swap(x, y);
      tr.add(pos[x], 1);
    } else {
      scanf("%d %d", &j, &k);
      if (dep[j] < dep[k]) swap(j, k);
      if (hd[j] == hd[k]) {
        if (tr.query(pos[j]) - tr.query(pos[k]) == 0)
          printf("%d\n", dep[j] - dep[k]);
        else
          printf("-1\n");
      } else {
        if (tr.query(pos[j]) - tr.query(pos[hd[j]] - 1) == 0 &&
            tr.query(pos[k]) - tr.query(pos[hd[k]] - 1) == 0)
          printf("%d\n", dep[j] + dep[k]);
        else
          printf("-1\n");
      }
    }
  }
  return 0;
}
