#include <bits/stdc++.h>
using namespace std;
int t, n, m, q, k;
int a[111111], b[111111];
int T[111111 << 2];
struct edg {
  int u, v, nx;
} E[555555];
int hd[111111], eid;
void adde(int u, int v) {
  E[eid].u = u;
  E[eid].v = v;
  E[eid].nx = hd[u];
  hd[u] = eid++;
}
int dep[111111], fa[111111], top[111111], tid[111111], sz[111111], son[111111],
    did;
void init() {
  eid = did = 0;
  memset(hd, -1, sizeof(hd));
  dep[0] = -1;
  son[0] = 0;
}
void dfs(int u, int f) {
  dep[u] = dep[f] + 1;
  fa[u] = f;
  sz[u] = 1;
  son[u] = -1;
  for (int i = hd[u]; i != -1; i = E[i].nx) {
    int v = E[i].v;
    if (v == f) continue;
    dfs(v, u);
    if (son[u] == -1 || sz[v] > sz[son[u]]) son[u] = v;
    sz[u] += sz[v];
  }
}
void dt(int u, int tp) {
  tid[u] = ++did;
  top[u] = tp;
  if (son[u] != -1) dt(son[u], tp);
  for (int i = hd[u]; ~i; i = E[i].nx) {
    int v = E[i].v;
    if (v == fa[u] || v == son[u]) continue;
    dt(v, v);
  }
}
void bt(int x, int l, int r) {
  if (l == r) {
    T[x] = 0;
    return;
  }
  int md = (l + r) >> 1;
  if (l == r) return;
  bt((x << 1), l, md);
  bt(((x << 1) | 1), md + 1, r);
}
void upd(int x, int l, int r, int p, int v) {
  if (l == r && l == p) {
    T[x] = v;
    return;
  }
  int md = (l + r) >> 1;
  if (p <= md)
    upd((x << 1), l, md, p, v);
  else
    upd(((x << 1) | 1), md + 1, r, p, v);
  T[x] = T[(x << 1)] + T[((x << 1) | 1)];
}
int qry(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return T[x];
  int md = (l + r) >> 1;
  if (R <= md)
    return qry((x << 1), l, md, L, R);
  else if (L > md)
    return qry(((x << 1) | 1), md + 1, r, L, R);
  return qry((x << 1), l, md, L, md) +
         qry(((x << 1) | 1), md + 1, r, md + 1, R);
}
int solve(int x, int y) {
  int ans = 0, fx = top[x], fy = top[y];
  while (fx != fy) {
    if (dep[fx] < dep[fy]) swap(x, y), swap(fx, fy);
    if (qry(1, 1, did, tid[fx], tid[x]) > 0) return -1;
    ans += tid[x] - tid[fx] + 1;
    x = fa[fx];
    fx = top[x];
  }
  if (x == y) return ans;
  if (dep[x] > dep[y]) swap(x, y);
  if (qry(1, 1, did, tid[son[x]], tid[y]) > 0) return -1;
  ans += tid[y] - tid[x];
  return ans;
}
int main() {
  while (~scanf("%d", &n)) {
    init();
    for (int i = (1); i <= (n - 1); ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      adde(u, v), adde(v, u);
    }
    dfs(1, 0);
    dt(1, 1);
    bt(1, 1, did);
    scanf("%d", &m);
    for (int i = (1); i <= (m); ++i) {
      int op, u, v;
      scanf("%d%d", &op, &u);
      if (op == 3) {
        scanf("%d", &v);
        int ans;
        if ((ans = solve(u, v)) == -1)
          printf("-1\n");
        else
          printf("%d\n", ans);
      } else {
        int x = E[(u - 1) * 2].u, y = E[(u - 1) * 2].v;
        int tg = dep[x] < dep[y] ? y : x;
        upd(1, 1, did, tid[tg], op == 1 ? 0 : 1);
      }
    }
  }
  return 0;
}
