#include <bits/stdc++.h>
using namespace std;
const int Maxn = 300000 + 10, inf = 0x3f3f3f3f;
const int Maxm = Maxn << 2;
int sum[Maxn];
int d[Maxn], top[Maxn], id[Maxn];
int f[Maxn], s[Maxn], son[Maxn];
int n, m, idcnt;
vector<int> e[Maxn];
struct Edge {
  int u, v;
} g[Maxn];
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
inline void push_up(int k) { sum[k] = sum[k << 1] + sum[k << 1 | 1]; }
void modify(int k, int l, int r, int pos, int v) {
  if (l == r) {
    sum[k] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(k << 1, l, mid, pos, v);
  else
    modify(k << 1 | 1, mid + 1, r, pos, v);
  push_up(k);
}
int query(int k, int l, int r, int x, int y) {
  if (x <= l && r <= y) return sum[k];
  int mid = (l + r) >> 1, ret = 0;
  if (x <= mid) ret = query(k << 1, l, mid, x, y);
  if (mid < y) ret += query(k << 1 | 1, mid + 1, r, x, y);
  return ret;
}
void dfs1(int x, int fa) {
  s[x] = 1, f[x] = fa, d[x] = d[fa] + 1;
  for (int i = 0; i < e[x].size(); ++i) {
    int y = e[x][i];
    if (y == fa) continue;
    dfs1(y, x);
    s[x] += s[y];
    if (s[y] > s[son[x]]) son[x] = y;
  }
}
void dfs2(int x, int topp) {
  top[x] = topp, id[x] = ++idcnt;
  if (!son[x]) return;
  dfs2(son[x], topp);
  for (int i = 0; i < e[x].size(); ++i) {
    int y = e[x][i];
    if (y == f[x] || y == son[x]) continue;
    dfs2(y, y);
  }
}
void modify_edge(int i, int v) {
  int x = g[i].u, y = g[i].v;
  if (d[x] < d[y]) swap(x, y);
  modify(1, 1, n, id[x], v);
}
int query_seq(int x, int y) {
  int tot = 0, cnt = 0;
  while (top[x] != top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    tot += id[x] - id[top[x]] + 1;
    cnt += query(1, 1, n, id[top[x]], id[x]);
    x = f[top[x]];
  }
  if (x == y) {
    if (cnt)
      return -1;
    else
      return tot;
  }
  if (d[x] > d[y]) swap(x, y);
  tot += id[y] - id[x];
  cnt += query(1, 1, n, id[x] + 1, id[y]);
  if (cnt)
    return -1;
  else
    return tot;
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    g[i].u = x, g[i].v = y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  m = read();
  while (m--) {
    int opt = read(), x = read();
    if (opt == 1) modify_edge(x, 0);
    if (opt == 2) modify_edge(x, 1);
    if (opt == 3) {
      int y = read();
      printf("%d\n", query_seq(x, y));
    }
  }
  return 0;
}
