#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 100;
int root, n, deg[N], ed[N][2], dep[N];
vector<int> adj[N], fen[N];
int nfe = 0, idf[N];
inline void dfs(int v, int par = root, int d = 1) {
  dep[v] = d;
  idf[v] = nfe;
  fen[nfe].push_back(0);
  for (int i = 0; i < (int)adj[v].size(); i++)
    if (adj[v][i] != par) dfs(adj[v][i], v, d + 1);
}
inline int ask(int t, int x) {
  int res = 0;
  for (; x > 0; x ^= x & -x) res += fen[t][x - 1];
  return res;
}
inline void add(int t, int x, int val) {
  for (; x <= (int)fen[t].size(); x += x & -x) fen[t][x - 1] += val;
}
int main() {
  scanf("%d", &n);
  memset(deg, 0, sizeof deg);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &ed[i][0], &ed[i][1]);
    adj[ed[i][0]].push_back(ed[i][1]);
    adj[ed[i][1]].push_back(ed[i][0]);
    deg[ed[i][0]]++;
    deg[ed[i][1]]++;
  }
  root = max_element(deg + 1, deg + n + 1) - deg;
  for (int i = 0; i < (int)adj[root].size(); i++) {
    dfs(adj[root][i]);
    for (int j = 0; j < (int)fen[nfe].size(); j++) add(nfe, j + 1, 1);
    nfe++;
  }
  int a, b, cmd, q, t, u, v;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &cmd);
    if (cmd == 1) {
      scanf("%d", &t);
      u = ed[t][0];
      v = ed[t][1];
      if (dep[u] < dep[v]) swap(u, v);
      add(idf[u], dep[u], 1);
    } else if (cmd == 2) {
      scanf("%d", &t);
      u = ed[t][0];
      v = ed[t][1];
      if (dep[u] < dep[v]) swap(u, v);
      add(idf[u], dep[u], -1);
    } else {
      scanf("%d%d", &a, &b);
      if (a == root || b == root) {
        if (a != root) swap(a, b);
        if (a == b)
          printf("0\n");
        else if (ask(idf[b], dep[b]) < dep[b])
          printf("-1\n");
        else
          printf("%d\n", dep[b] - dep[a]);
      } else if (idf[a] == idf[b]) {
        if (dep[a] < dep[b]) swap(a, b);
        if (ask(idf[a], dep[a]) - ask(idf[b], dep[b]) < dep[a] - dep[b])
          printf("-1\n");
        else
          printf("%d\n", dep[a] - dep[b]);
      } else {
        if (ask(idf[a], dep[a]) + ask(idf[b], dep[b]) < dep[a] + dep[b])
          printf("-1\n");
        else
          printf("%d\n", dep[a] + dep[b]);
      }
    }
  }
  return 0;
}
