#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, own[N], id = 1, m, a, b, dfs_time = 1, st[N], ed[N], type, BIT[N], ti[N],
               bk[N];
vector<pair<int, int> > g[N];
void add(int idx, int val) {
  while (idx < n) {
    BIT[idx] += val;
    idx += (idx & -idx);
  }
}
int get(int idx) {
  int res = 0;
  while (idx > 0) {
    res += BIT[idx];
    idx -= (idx & -idx);
  }
  return res;
}
void dfs(int u, int p, int e) {
  own[u] = id;
  bk[e] = dfs_time;
  ti[u] = dfs_time++;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (v == p) continue;
    dfs(v, u, g[u][i].second);
  }
}
int root = -1, mx = -1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d", &a, &b);
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
    add(i, 1);
  }
  for (int i = 1; i <= n; i++) {
    if ((int)g[i].size() > mx) {
      root = i;
      mx = (int)g[i].size();
    }
  }
  for (int i = 0; i < g[root].size(); ++i) {
    st[id] = dfs_time;
    dfs(g[root][i].first, root, g[root][i].second);
    ed[id] = dfs_time - 1;
    id++;
  }
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &a);
      a = bk[a];
      add(a, 1);
    }
    if (type == 2) {
      scanf("%d", &a);
      a = bk[a];
      add(a, -1);
    }
    if (type == 3) {
      scanf("%d%d", &a, &b);
      if (a == b) {
        puts("0");
      } else if (root == a || root == b) {
        if (root == b) {
          swap(a, b);
        }
        int need = ti[b] - st[own[b]] + 1;
        if (get(ti[b]) - get(st[own[b]] - 1) == need) {
          printf("%d\n", need);
        } else {
          printf("-1\n");
        }
      } else if (own[a] == own[b]) {
        if (ti[a] > ti[b]) swap(a, b);
        int need = ti[b] - ti[a];
        if (get(ti[b]) - get(ti[a]) == need) {
          printf("%d\n", need);
        } else {
          puts("-1");
        }
      } else {
        int need = ti[a] - st[own[a]] + ti[b] - st[own[b]] + 2;
        if (get(ti[b]) - get(st[own[b]] - 1) + get(ti[a]) -
                get(st[own[a]] - 1) ==
            need) {
          printf("%d\n", need);
        } else {
          puts("-1");
        }
      }
    }
  }
  return 0;
}
