#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
int n, m, tot, cnt;
int wt[maxn], val[maxn], weight[maxn], fa[maxn], deep[maxn], top[maxn],
    id[maxn], wson[maxn], head[maxn];
struct node {
  int to, next, from;
} e[maxn * 2], a[maxn];
struct segTree {
  int l, r, sum1, sum2;
} tree[maxn * 4];
void add(int x, int y) {
  e[++tot].to = y;
  e[tot].from = x;
  e[tot].next = head[x];
  head[x] = tot;
}
void dfs1(int x, int f, int dep) {
  fa[x] = f;
  deep[x] = dep;
  weight[x] = 1;
  int maxx = -1;
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y == f) continue;
    dfs1(y, x, dep + 1);
    weight[x] += weight[y];
    if (weight[y] > maxx) {
      maxx = weight[y];
      wson[x] = y;
    }
  }
}
void dfs2(int x, int topf) {
  top[x] = topf;
  id[x] = ++cnt;
  wt[cnt] = val[x];
  if (!wson[x]) return;
  dfs2(wson[x], topf);
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!id[y]) dfs2(y, y);
  }
}
void pushup(int now) {
  int ls = now * 2, rs = now * 2 + 1;
  tree[now].sum1 = tree[ls].sum1 + tree[rs].sum1;
  tree[now].sum2 = tree[ls].sum2 + tree[rs].sum2;
}
void build(int now, int l, int r) {
  tree[now].l = l, tree[now].r = r;
  if (l == r) {
    tree[now].sum1 = 1;
    tree[now].sum2 = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(now * 2, l, mid);
  build(now * 2 + 1, mid + 1, r);
  pushup(now);
}
void change(int now, int x, int val) {
  if (tree[now].l == tree[now].r) {
    tree[now].sum1 = val;
    tree[now].sum2 = val ^ 1;
    return;
  }
  int mid = (tree[now].l + tree[now].r) / 2;
  if (x <= mid)
    change(now * 2, x, val);
  else
    change(now * 2 + 1, x, val);
  pushup(now);
}
segTree query(int now, int l, int r) {
  segTree ans;
  ans.sum1 = ans.sum2 = 0;
  if (l <= tree[now].l && r >= tree[now].r) return tree[now];
  int mid = (tree[now].l + tree[now].r) / 2;
  if (l > mid) return query(now * 2 + 1, l, r);
  if (r <= mid) return query(now * 2, l, r);
  segTree ans1 = query(now * 2, l, r), ans2 = query(now * 2 + 1, l, r);
  ans.sum1 = ans1.sum1 + ans2.sum1;
  ans.sum2 = ans1.sum2 + ans2.sum2;
  return ans;
}
segTree qrange(int x, int y) {
  segTree ans;
  ans.sum1 = 0, ans.sum2 = 0;
  while (top[x] != top[y]) {
    if (deep[top[x]] < deep[top[y]]) swap(x, y);
    segTree ret = query(1, id[top[x]], id[x]);
    ans.sum1 += ret.sum1;
    ans.sum2 += ret.sum2;
    x = fa[top[x]];
  }
  if (x == y) return ans;
  if (deep[x] > deep[y]) swap(x, y);
  segTree ret = query(1, id[x] + 1, id[y]);
  ans.sum1 += ret.sum1;
  ans.sum2 += ret.sum2;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
    a[i].from = x, a[i].to = y;
  }
  dfs1(1, 0, 1);
  dfs2(1, 1);
  build(1, 1, n);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int x;
      scanf("%d", &x);
      int p = a[x].from;
      if (deep[a[x].from] < deep[a[x].to]) p = a[x].to;
      change(1, id[p], 1);
    }
    if (op == 2) {
      int x;
      scanf("%d", &x);
      int p = a[x].from;
      if (deep[a[x].from] < deep[a[x].to]) p = a[x].to;
      change(1, id[p], 0);
    }
    if (op == 3) {
      int x, y;
      scanf("%d%d", &x, &y);
      segTree ans = qrange(x, y);
      if (ans.sum2)
        printf("-1\n");
      else
        printf("%d\n", ans.sum1);
    }
  }
  return 0;
}
