#include <bits/stdc++.h>
using namespace std;
int n, m, root;
int ui[200011], vi[200011];
struct edge {
  int u, v, nxt;
} a[200011];
int tot, fir[100011];
void New(int from, int to) {
  a[++tot].u = from;
  a[tot].v = to;
  a[tot].nxt = fir[from];
  fir[from] = tot;
}
int cnt;
int f[100011];
int son[100011];
int siz[100011];
int dep[100011];
int top[100011];
int id[100011];
void dfs1(int w, int fa, int d) {
  f[w] = fa;
  dep[w] = d;
  siz[w] = 1;
  int now = fir[w];
  while (now) {
    if (a[now].v != fa) {
      dfs1(a[now].v, w, d + 1);
      siz[w] += siz[a[now].v];
      if (siz[a[now].v] > siz[son[w]]) son[w] = a[now].v;
    }
    now = a[now].nxt;
  }
}
void dfs2(int w, int tp) {
  top[w] = tp;
  id[w] = ++cnt;
  if (son[w]) dfs2(son[w], tp);
  int now = fir[w];
  while (now) {
    if (a[now].v != f[w] && a[now].v != son[w]) dfs2(a[now].v, a[now].v);
    now = a[now].nxt;
  }
}
int t[800011];
void change(int k, int l, int r, int w, int sum) {
  if (l == r) {
    t[k] = sum;
    return;
  }
  int mid = (l + r) >> 1;
  if (w <= mid)
    change(k * 2, l, mid, w, sum);
  else
    change(k * 2 + 1, mid + 1, r, w, sum);
  t[k] = t[k * 2] + t[k * 2 + 1];
}
int query(int k, int l, int r, int L, int R) {
  if (l > R || r < L) return 0;
  if (l >= L && r <= R) return t[k];
  int mid = (l + r) >> 1;
  return query(k * 2, l, mid, L, R) + query(k * 2 + 1, mid + 1, r, L, R);
}
void Query(int x, int y) {
  int ans = 0;
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    if (query(1, 1, n, id[top[x]], id[x])) {
      printf("-1\n");
      return;
    } else
      ans += id[x] - id[top[x]] + 1;
    x = f[top[x]];
  }
  if (dep[x] < dep[y]) swap(x, y);
  if (x != y) {
    if (query(1, 1, n, id[y] + 1, id[x])) {
      printf("-1\n");
      return;
    } else
      ans += id[x] - id[y];
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d", &n);
  root = 1;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &ui[i], &vi[i]);
    New(ui[i], vi[i]);
    New(vi[i], ui[i]);
  }
  dfs1(root, 0, 1);
  dfs2(root, root);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int opt, x, y;
    scanf("%d", &opt);
    switch (opt) {
      case 1: {
        scanf("%d", &x);
        int pot;
        if (dep[ui[x]] > dep[vi[x]])
          pot = ui[x];
        else
          pot = vi[x];
        change(1, 1, n, id[pot], 0);
        break;
      }
      case 2: {
        scanf("%d", &x);
        int pot;
        if (dep[ui[x]] > dep[vi[x]])
          pot = ui[x];
        else
          pot = vi[x];
        change(1, 1, n, id[pot], 1);
        break;
      }
      case 3: {
        scanf("%d%d", &x, &y);
        Query(x, y);
        break;
      }
    }
  }
  return 0;
}
