#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}
void fc() {
  fclose(stdin);
  fclose(stdout);
}
inline long long ccin() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline void cou(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) cou(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 3e5 + 10;
const long long inf = 1e16;
const int maxm = 5e5 + 10;
int n, m;
struct node {
  int top;
  int fat;
  int siz;
  int zson;
  int dep;
} all[maxn];
int dfn[maxn], rdfn[maxn], ans[maxn], shu;
int fat1[maxn][60];
int lg2[maxn];
vector<int> yuan[maxn];
void add1(int u, int v) { yuan[u].push_back(v); }
struct xnode {
  int lo;
  int ro;
  int zhi;
} tr[maxn * 4];
void dfs(int now, int fa) {
  all[now].dep = all[fa].dep + 1;
  all[now].fat = fa;
  all[now].siz = 1;
  for (int i = 0; i < yuan[now].size(); i++) {
    int v = yuan[now][i];
    if (v == fa) continue;
    dfs(v, now);
    all[now].siz += all[v].siz;
    if (all[v].siz >= all[all[now].zson].siz) all[now].zson = v;
  }
}
void dfs1(int now, int tp) {
  all[now].top = tp;
  dfn[now] = ++shu;
  rdfn[shu] = now;
  if (all[now].zson) dfs1(all[now].zson, tp);
  for (int i = 0; i < yuan[now].size(); i++) {
    int v = yuan[now][i];
    if (v == all[now].fat || v == all[now].zson) continue;
    dfs1(v, v);
  }
}
struct edge {
  int lo;
  int ro;
} side[maxm];
void pushup1(int now, int lo, int ro) { tr[now].zhi = tr[lo].zhi + tr[ro].zhi; }
void build(int now, int lo, int ro) {
  tr[now].lo = lo;
  tr[now].ro = ro;
  if (lo == ro) {
    tr[now].zhi = 1;
    return;
  }
  build(now * 2, lo, ((lo + ro) >> 1));
  build(now * 2 + 1, ((lo + ro) >> 1) + 1, ro);
  pushup1(now, now * 2, now * 2 + 1);
}
void upd(int now, int pos, int zhi) {
  if (tr[now].lo == tr[now].ro) {
    tr[now].zhi = zhi;
    return;
  }
  int mid1 = (tr[now].lo + tr[now].ro) / 2;
  if (mid1 < pos)
    upd(now * 2 + 1, pos, zhi);
  else
    upd(now * 2, pos, zhi);
  pushup1(now, now * 2, now * 2 + 1);
}
void lcadfs(int now, int fa) {
  fat1[now][0] = all[now].fat;
  for (int i = 1; i <= lg2[all[now].dep]; i++)
    fat1[now][i] = fat1[fat1[now][i - 1]][i - 1];
  for (int i = 0; i < yuan[now].size(); i++) {
    int v = yuan[now][i];
    if (v == all[now].fat) continue;
    lcadfs(v, now);
  }
}
int lca(int u, int v) {
  if (all[v].dep < all[u].dep) swap(v, u);
  while (all[v].dep > all[u].dep) {
    v = fat1[v][lg2[all[v].dep - all[u].dep] - 1];
  }
  if (u == v) return u;
  for (int i = lg2[all[v].dep]; i >= 0; i--) {
    if (fat1[u][i] != fat1[v][i]) {
      u = fat1[u][i];
      v = fat1[v][i];
    }
  }
  return fat1[v][0];
}
long long req(int now, int lo, int ro) {
  if (tr[now].lo >= lo && tr[now].ro <= ro)
    return tr[now].zhi;
  else if (tr[now].lo > ro || tr[now].ro < lo)
    return 0;
  int mid1 = (tr[now].lo + tr[now].ro) / 2;
  long long ans1 = 0;
  if (lo <= mid1) ans1 += req(now * 2, lo, ro);
  if (mid1 <= ro) ans1 += req(now * 2 + 1, lo, ro);
  return ans1;
}
long long reqsum(int now1, int now2) {
  long long res = 0;
  int tp1 = all[now1].top, tp2 = all[now2].top;
  while (tp1 != tp2) {
    if (all[tp1].dep < all[tp2].dep) swap(tp1, tp2), swap(now1, now2);
    res += req(1, dfn[tp1], dfn[now1]);
    now1 = all[tp1].fat;
    tp1 = all[now1].top;
  }
  if (all[now1].dep < all[now2].dep) swap(now1, now2);
  res += req(1, dfn[now2] + 1, dfn[now1]);
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 1; i <= 1e5; i++) {
    lg2[i] = lg2[i - 1];
    if (i == (1 << lg2[i])) lg2[i]++;
  }
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a1, a2;
    cin >> a1 >> a2;
    side[i].lo = a1;
    side[i].ro = a2;
    add1(a1, a2);
    add1(a2, a1);
  }
  dfs(1, 0);
  lcadfs(1, 0);
  dfs1(1, 1);
  build(1, 1, shu);
  cin >> m;
  while (m--) {
    int tmp;
    cin >> tmp;
    if (tmp == 1) {
      int u;
      cin >> u;
      int a1 = side[u].lo;
      int a2 = side[u].ro;
      int ch = (all[a1].dep > all[a2].dep) ? a1 : a2;
      upd(1, dfn[ch], 1);
    } else if (tmp == 2) {
      int u;
      cin >> u;
      int a1 = side[u].lo, a2 = side[u].ro;
      int ch = (all[a1].dep > all[a2].dep) ? a1 : a2;
      upd(1, dfn[ch], 0);
    } else {
      int u, v;
      cin >> u >> v;
      int zu = lca(u, v);
      long long ans1 = reqsum(u, v);
      if (ans1 == all[u].dep + all[v].dep - 2 * all[zu].dep)
        cout << ans1 << '\n';
      else
        cout << -1 << '\n';
    }
  }
  return 0;
}
