#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int dep[maxn], dfn[maxn], dcnt, top[maxn], siz[maxn], fa[maxn], son[maxn];
int n, ide[maxn];
struct edge {
  int v, nxt, id;
} e[maxn << 1];
int head[maxn], kt;
struct SegmentTree {
  int sum[maxn << 2];
  void build(int u, int l, int r) {
    sum[u] = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
  }
  void modify(int u, int l, int r, int x) {
    if (l == r) return void(sum[u] ^= 1);
    int mid = (l + r) >> 1;
    if (x <= mid)
      modify(u << 1, l, mid, x);
    else
      modify(u << 1 | 1, mid + 1, r, x);
    sum[u] = sum[u << 1] & sum[u << 1 | 1];
  }
  int query(int u, int l, int r, int x, int y) {
    if (x <= l && r <= y) return sum[u];
    int mid = (l + r) >> 1, res = 1;
    if (x <= mid) res &= query(u << 1, l, mid, x, y);
    if (y > mid) res &= query(u << 1 | 1, mid + 1, r, x, y);
    return res;
  }
} wife;
inline void addedge(int u, int v, int id) {
  e[++kt] = (edge){v, head[u], id};
  head[u] = kt;
}
void dfs1(int u, int f) {
  fa[u] = f;
  dep[u] = dep[f] + 1;
  siz[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    ide[e[i].id] = v;
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int topf) {
  top[u] = topf;
  dfn[u] = ++dcnt;
  if (!son[u]) return;
  dfs2(son[u], topf);
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].v != fa[u] && e[i].v != son[u]) dfs2(e[i].v, e[i].v);
}
int qutree(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    if (!wife.query(1, 1, n, dfn[top[u]], dfn[u])) return -1;
    u = fa[top[u]];
  }
  if (dep[u] > dep[v]) swap(u, v);
  if (u != v && !wife.query(1, 1, n, dfn[u] + 1, dfn[v])) return -1;
  return u;
}
template <typename T>
inline void read(T &x) {
  char c;
  int f = 1;
  while (!isdigit(c = getchar())) (c == '-') && (f = -1);
  x = c ^ 48;
  while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);
  x *= f;
}
int main() {
  int u, v, q, opt;
  read(n);
  for (int i = 1; i < n; ++i)
    read(u), read(v), addedge(u, v, i), addedge(v, u, i);
  dfs1(1, 0);
  dfs2(1, 1);
  read(q);
  wife.build(1, 1, n);
  while (q--) {
    read(opt);
    read(u);
    if (opt == 1 || opt == 2)
      wife.modify(1, 1, n, dfn[ide[u]]);
    else {
      read(v);
      opt = qutree(u, v);
      if (opt == -1)
        puts("-1");
      else
        printf("%d\n", dep[u] + dep[v] - dep[opt] * 2);
    }
  }
  return 0;
}
