#include <bits/stdc++.h>
using namespace std;
int n, q, now, tmp;
int T[4 * 100005];
int a[100005], b[100005], tp;
int t, u, v;
int L[100005], P[100005][20];
int chain[100005], id[100005], head[100005];
int Sb[100005], Sn[100005];
vector<int> E[100005];
void dfs(int node, int pr) {
  L[node] = L[pr] + 1;
  P[node][0] = pr;
  Sb[node] = 1;
  for (auto i : E[node]) {
    if (i == pr) continue;
    dfs(i, node);
    Sb[node] += Sb[i];
    if (Sb[Sn[node]] < Sb[i]) Sn[node] = i;
  }
}
void build_chain(int node, int pr) {
  chain[node] = now;
  id[node] = ++tmp;
  if (head[now] == 0) head[now] = node;
  if (Sn[node] == 0) return;
  build_chain(Sn[node], node);
  for (auto i : E[node])
    if (i != pr && Sn[node] != i) now++, build_chain(i, node);
}
void build_lca() {
  for (int i = 1; (1 << i) <= n; i++)
    for (int h = 1; h <= n; h++) P[h][i] = -1;
  for (int i = 1; (1 << i) <= n; i++)
    for (int h = 1; h <= n; h++)
      if (P[h][i - 1] != -1) P[h][i] = P[P[h][i - 1]][i - 1];
}
void upd(int x, int y, int l, int r, int node) {
  if (l == r) {
    T[node] = y;
    return;
  }
  if (x <= (l + r) / 2)
    upd(x, y, l, (l + r) / 2, node * 2);
  else
    upd(x, y, (l + r) / 2 + 1, r, node * 2 + 1);
  T[node] = T[node * 2] + T[node * 2 + 1];
}
int lca(int a, int b) {
  if (L[a] < L[b]) swap(a, b);
  for (int i = 18; i >= 0; i--)
    if (L[a] - (1 << i) >= L[b]) a = P[a][i];
  if (a == b) return a;
  for (int i = 18; i >= 0; i--)
    if (P[a][i] != P[b][i]) a = P[a][i], b = P[b][i];
  return P[a][0];
}
int tap(int a, int b, int l, int r, int node) {
  if (a > b) return 0;
  if (a > r || b < l) return 0;
  if (a <= l && b >= r) return T[node];
  return tap(a, b, l, (l + r) / 2, node * 2) +
         tap(a, b, (l + r) / 2 + 1, r, node * 2 + 1);
}
void get(int a, int b) {
  while (1) {
    if (chain[a] == chain[b]) {
      tp += tap(id[b] + 1, id[a], 1, n, 1);
      break;
    }
    tp += tap(id[head[chain[a]]], id[a], 1, n, 1);
    a = head[chain[a]];
    a = P[a][0];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    E[a[i]].push_back(b[i]);
    E[b[i]].push_back(a[i]);
  }
  dfs(1, -1);
  build_lca();
  build_chain(1, -1);
  for (int i = 1; i <= n; i++) upd(i, 1, 1, n, 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &t, &u);
    if (t == 1) {
      int x = a[u];
      int y = b[u];
      if (L[x] < L[y]) swap(x, y);
      upd(id[x], 1, 1, n, 1);
    } else if (t == 2) {
      int x = a[u];
      int y = b[u];
      if (L[x] < L[y]) swap(x, y);
      upd(id[x], 0, 1, n, 1);
    } else {
      scanf("%d", &v);
      int lc = lca(u, v);
      int dist = L[u] + L[v] - 2 * L[lc];
      tp = 0;
      get(u, lc);
      get(v, lc);
      if (tp != dist) tp = -1;
      printf("%d\n", tp);
    }
  }
}
