#include <bits/stdc++.h>
using namespace std;
int n, head[400005], tot, rk[400005], m, chan[400005], lca;
struct node {
  int to, next, id;
  node(int to = 0, int next = 0, int id = 0) : to(to), next(next), id(id) {}
} e[400005];
struct node1 {
  int fa, top, id, d, son, size, w;
} s[400005];
struct node2 {
  int l, r;
  bool col;
} t[400005 << 1];
int read() {
  int w = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    w = (w << 3) + (w << 1) + (c ^ 48);
    c = getchar();
  }
  return w * f;
}
void adde(int u, int v, int i) {
  e[++tot] = node(v, head[u], i);
  head[u] = tot;
}
void dfs1(int u) {
  s[u].d = s[s[u].fa].d + 1, s[u].size = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v != s[u].fa) {
      s[v].fa = u;
      dfs1(v);
      s[u].size += s[v].size;
      chan[e[i].id] = v;
      if (s[s[u].son].size < s[v].size) s[u].son = v;
    }
  }
}
void dfs2(int u, int tp) {
  s[u].top = tp, s[u].id = ++tot, rk[tot] = u;
  if (s[u].son) dfs2(s[u].son, tp);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v != s[u].fa && v != s[u].son) dfs2(v, v);
  }
}
void build(int i, int l, int r) {
  t[i].l = l, t[i].r = r;
  if (l == r) return;
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
}
void update(int i) { t[i].col = t[i << 1].col | t[i << 1 | 1].col; }
void ch(int i, int dis, int k) {
  if (t[i].l == t[i].r) {
    t[i].col = k;
    return;
  }
  if (t[i << 1].r >= dis)
    ch(i << 1, dis, k);
  else
    ch(i << 1 | 1, dis, k);
  update(i);
}
bool search(int i, int l, int r) {
  if (t[i].l >= l && t[i].r <= r) return t[i].col;
  bool ans = 0;
  if (t[i << 1].r >= l) ans |= search(i << 1, l, r);
  if (t[i << 1 | 1].l <= r) ans |= search(i << 1 | 1, l, r);
  return ans;
}
bool judge(int u, int v) {
  bool ans = 0;
  while (s[u].top != s[v].top) {
    if (s[s[u].top].d < s[s[v].top].d) swap(u, v);
    ans |= search(1, s[s[u].top].id, s[u].id);
    u = s[s[u].top].fa;
  }
  if (s[u].id > s[v].id) swap(u, v);
  lca = u;
  if (s[u].id < s[v].id) ans |= search(1, s[u].id + 1, s[v].id);
  return ans;
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    adde(u, v, i), adde(v, u, i);
  }
  dfs1(1);
  tot = 0;
  dfs2(1, 1);
  build(1, 1, n);
  m = read();
  for (int i = 1; i <= m; i++) {
    int op = read();
    if (op == 1)
      ch(1, s[chan[read()]].id, 0);
    else if (op == 2)
      ch(1, s[chan[read()]].id, 1);
    else {
      int u = read(), v = read();
      if (judge(u, v))
        puts("-1");
      else
        printf("%d\n", s[u].d + s[v].d - s[lca].d * 2);
    }
  }
  return 0;
}
