#include <bits/stdc++.h>
using namespace std;
vector<int> sum[100500], tree[100500], edge_num[100500];
int k, cnt;
int belong_edge[100500], belong_node[100500], d[100500];
int num_edge[100500], num_node[100500], color[100500];
struct EDGE {
  int u, v;
} edge[100500];
inline int lowbit(int x) { return x & (-x); }
inline void update(int num, int x, int c, int n) {
  for (; x <= n; x += lowbit(x)) sum[num][x] += c;
}
inline int query(int num, int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += sum[num][x];
  return ans;
}
void dfs(int now, int pre) {
  int len = tree[now].size(), y;
  for (int i = 0; i < len; i++) {
    y = tree[now][i];
    if (y == pre) continue;
    if (pre == -1) {
      ++k;
      cnt = 0;
      sum[k].push_back(0);
    }
    d[y] = d[now] + 1;
    num_edge[edge_num[now][i]] = ++cnt;
    num_node[y] = cnt;
    sum[k].push_back(0);
    belong_node[y] = k;
    belong_edge[edge_num[now][i]] = k;
    dfs(y, now);
  }
}
int main(void) {
  int op, n, q, x, y;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    tree[x].push_back(y);
    edge_num[x].push_back(i);
    tree[y].push_back(x);
    edge_num[y].push_back(i);
    edge[i].u = x;
    edge[i].v = y;
  }
  int root = 1;
  for (int i = 2; i <= n; i++)
    if (tree[i].size() > 2) {
      root = i;
      break;
    }
  dfs(root, -1);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op < 3) {
      scanf("%d", &x);
      int num1 = belong_edge[x], num2 = num_edge[x];
      if (op == 1)
        update(num1, num2, -1, sum[num1].size() - 1);
      else
        update(num1, num2, 1, sum[num1].size() - 1);
    } else {
      scanf("%d%d", &x, &y);
      if (y == root) swap(x, y);
      if (x == root) {
        if (y == root)
          printf("0\n");
        else {
          int num1 = belong_node[y], num2 = num_node[y];
          if (query(num1, num2) == 0)
            printf("%d\n", d[y]);
          else
            printf("-1\n");
        }
      } else {
        if (d[y] > d[x]) swap(x, y);
        int num1 = belong_node[x], num2 = num_node[x];
        int dis1 = query(num1, num2);
        num1 = belong_node[y], num2 = num_node[y];
        int dis2 = query(num1, num2);
        if (belong_node[x] == belong_node[y]) {
          if (dis1 == dis2)
            printf("%d\n", d[x] - d[y]);
          else
            printf("-1\n");
        } else {
          if (dis1 == 0 && dis2 == 0)
            printf("%d\n", d[x] + d[y]);
          else
            printf("-1\n");
        }
      }
    }
  }
  return 0;
}
