#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[100010];
int deg[100010], col[100010], tree[100010], posedge[100010],
    idx = 1, comp[100010], pos[100010], h[100010];
void dfsinit(int u, int par, int compid, int h1) {
  comp[u] = compid;
  h[u] = h1;
  for (auto& v : g[u]) {
    if (v.first == par) continue;
    pos[v.first] = idx;
    posedge[v.second] = idx++;
    dfsinit(v.first, u, compid, 1 + h1);
  }
}
void upd(int idx, int v) {
  while (idx < 100010) {
    tree[idx] += v;
    idx += (idx & (-idx));
  }
}
int query(int idx) {
  int y = 0;
  while (idx > 0) {
    y += tree[idx];
    idx -= (idx & (-idx));
  }
  return y;
}
int queryup(int node) { return query(pos[node]) - query(comp[node] - 1); }
int main() {
  int type, n, root = 1, m, id;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    g[a].push_back({b, i});
    ++deg[a];
    swap(a, b);
    g[a].push_back({b, i});
    ++deg[a];
  }
  for (int i = 1; i <= n; ++i) {
    if (deg[i] > 2) {
      root = i;
    }
  }
  for (auto& start : g[root]) {
    pos[start.first] = idx;
    posedge[start.second] = idx++;
    dfsinit(start.first, root, idx - 1, 1);
  }
  h[root] = 0;
  comp[root] = 0;
  pos[root] = 0;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &type);
    if (type <= 2) {
      scanf("%d", &id);
      upd(posedge[id], type - 1 - col[id]);
      col[id] = type - 1;
    }
    if (type == 3) {
      int a, b, diff, possible;
      scanf("%d", &a);
      scanf("%d", &b);
      if (comp[a] == comp[b]) {
        diff = h[a] - h[b];
        if (diff < 0) diff = -diff;
        possible = (queryup(a) == queryup(b));
      } else {
        diff = h[a] + h[b];
        possible = (queryup(a) == 0 && queryup(b) == 0);
      }
      if (!possible) diff = -1;
      printf("%d\n", diff);
    }
  }
  return 0;
}
