#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct _edge {
  int u, v;
};
vector<int> ide[maxn];
_edge e[maxn];
int n, idr, _list[maxn], m, col[maxn], pos[maxn], dep[maxn], q, cmd, bit[maxn],
    ance[maxn];
void dfs(int rx, int x, int tmp) {
  col[x] = tmp;
  int y;
  for (vector<int>::iterator it = ide[x].begin(); it != ide[x].end(); it++) {
    y = e[*it].u + e[*it].v - x;
    if (y != rx) {
      ance[y] = *it;
      dep[y] = dep[x] + 1;
      _list[++m] = *it;
      pos[*it] = m;
      if (rx == 0) tmp++;
      dfs(x, y, tmp);
    }
  }
}
void update(int x, int v) {
  while (x < n) {
    bit[x] += v;
    x += x & -x;
  }
}
int get(int x) {
  int ans = 0;
  while (x) {
    ans += bit[x];
    x -= x & -x;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int u, v, i = 1; i < n; i++) {
    scanf("%d%d", &e[i].u, &e[i].v);
    ide[e[i].u].push_back(i);
    ide[e[i].v].push_back(i);
  }
  idr = 0;
  for (int i = 1; i <= n; i++) {
    if (ide[idr].size() < ide[i].size()) {
      idr = i;
    }
  }
  dfs(0, idr, 0);
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d", &cmd);
    if (cmd == 1) {
      scanf("%d", &u);
      update(pos[u], -1);
    } else if (cmd == 2) {
      scanf("%d", &u);
      update(pos[u], 1);
    } else {
      int cnt = 0, l, r;
      scanf("%d%d", &u, &v);
      if (dep[u] > dep[v]) swap(u, v);
      if (u == idr || (col[u] == col[v])) {
        r = pos[ance[v]];
        l = r - (dep[v] - dep[u]) + 1;
        cnt = get(r) - get(l - 1);
        if (cnt == 0)
          printf("%d\n", dep[v] - dep[u]);
        else
          printf("-1\n");
      } else {
        r = pos[ance[v]];
        l = r - dep[v] + 1;
        cnt += get(r) - get(l - 1);
        r = pos[ance[u]];
        l = r - dep[u] + 1;
        cnt += get(r) - get(l - 1);
        if (cnt == 0)
          printf("%d\n", dep[u] + dep[v]);
        else
          printf("-1\n");
      }
    }
  }
}
