#include <bits/stdc++.h>
using namespace std;
int bit[100010], n;
inline int lowbit(int x) { return x & -x; }
inline void modify(int pos, int add) {
  for (int i = pos; i <= n; i += lowbit(i)) bit[i] += add;
}
inline int query(int pos) {
  int res = 0;
  for (int i = pos; i > 0; i -= lowbit(i)) res += bit[i];
  return res;
}
inline int getSum(int l, int r) {
  if (l > r) return 0;
  return query(r) - query(l - 1);
}
vector<pair<int, int> > g[100010];
int belong[100010], id[100010], dep[100010], idx, top[100010];
void dfs(int u, int fa) {
  for (pair<int, int>& e : g[u]) {
    int v = e.first, edge_id = e.second;
    if (v == fa) continue;
    if (fa == -1) {
      top[v] = v;
    } else {
      top[v] = top[u];
    }
    dep[v] = dep[u] + 1;
    id[v] = ++idx;
    modify(id[v], 1);
    belong[edge_id] = v;
    dfs(v, u);
  }
}
int main() {
  int u, v, root, max_deg = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(pair<int, int>(v, i));
    g[v].push_back(pair<int, int>(u, i));
  }
  for (int v = 1; v <= n; v++) {
    if ((int)g[v].size() > max_deg) {
      root = v;
      max_deg = (int)g[v].size();
    }
  }
  dfs(root, -1);
  int m, o, _id;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &o);
    if (o == 1) {
      scanf("%d", &_id);
      modify(id[belong[_id]], 1);
    } else if (o == 2) {
      scanf("%d", &_id);
      modify(id[belong[_id]], -1);
    } else {
      scanf("%d%d", &u, &v);
      int ans;
      if (v == root) swap(u, v);
      if (u == root) {
        ans = getSum(id[top[v]], id[v]);
        if (ans != dep[v]) ans = -1;
      } else if (top[u] == top[v]) {
        if (dep[u] > dep[v]) swap(u, v);
        ans = getSum(id[u] + 1, id[v]);
        if (ans != dep[v] - dep[u]) ans = -1;
      } else {
        ans = getSum(id[top[v]], id[v]) + getSum(id[top[u]], id[u]);
        if (ans != dep[v] + dep[u]) ans = -1;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
