#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, nxt[N << 1], to[N << 1], head[N], tot, u[N][2], sum[N << 2];
int seg[N], son[N], father[N], top[N], siz[N], dep[N], ans;
inline void add(int x, int y) {
  nxt[++tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
inline void dfs1(int x, int fa) {
  father[x] = fa;
  dep[x] = dep[fa] + 1, siz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) continue;
    dfs1(y, x);
    siz[x] += siz[y];
    if (siz[y] > siz[son[x]]) son[x] = y;
  }
}
inline void dfs2(int x, int topf) {
  top[x] = topf;
  seg[x] = ++seg[0];
  if (!son[x]) return;
  dfs2(son[x], topf);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (top[y]) continue;
    dfs2(y, y);
  }
}
void build(int k, int l, int r) {
  if (l == r) {
    sum[k] = 1;
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  sum[k] = sum[k << 1] + sum[k << 1 | 1];
}
void change(int k, int l, int r, int x, int z) {
  if (z && sum[k] == r - l + 1) return;
  if (l == r) {
    sum[k] = z;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    change(k << 1, l, mid, x, z);
  else
    change(k << 1 | 1, mid + 1, r, x, z);
  sum[k] = sum[k << 1] + sum[k << 1 | 1];
}
bool query1(int k, int l, int r, int x, int y) {
  if (x <= l && y >= r) {
    if (sum[k] == r - l + 1) {
      ans += sum[k];
      return 1;
    }
    return 0;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    if (!query1(k << 1, l, mid, x, y)) return 0;
  if (y > mid)
    if (!query1(k << 1 | 1, mid + 1, r, x, y)) return 0;
  return 1;
}
inline void change1(int x, int z) {
  int xx = u[x][0], yy = u[x][1];
  if (father[xx] == yy)
    change(1, 1, n, seg[xx], z);
  else
    change(1, 1, n, seg[yy], z);
}
inline bool query(int x, int y) {
  int fx = top[x], fy = top[y];
  while (fx != fy) {
    if (dep[fx] < dep[fy]) swap(x, y), swap(fx, fy);
    if (!query1(1, 1, n, seg[fx], seg[x])) return 0;
    x = father[fx];
    fx = top[x];
  }
  if (dep[x] > dep[y]) swap(x, y);
  if (seg[x] + 1 <= seg[y])
    if (!query1(1, 1, n, seg[x] + 1, seg[y])) return 0;
  return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    u[i][0] = x;
    u[i][1] = y;
    add(x, y), add(y, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  build(1, 1, n);
  tot = 0;
  cin >> m;
  while (m--) {
    int k, x;
    cin >> k >> x;
    if (k == 1)
      change1(x, 1);
    else if (k == 2)
      change1(x, 0);
    else {
      int y;
      cin >> y;
      ans = 0;
      if (query(x, y)) {
        cout << ans << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
}
