#include <bits/stdc++.h>
using namespace std;
int n, m, in[100005], root, Gnum[100005], num[100005], GG, mx;
pair<int, int> E[100005];
vector<int> v[100005];
vector<vector<int> > tree;
void dfs(int now, int pre) {
  num[now] = num[pre] + 1;
  mx = num[now];
  Gnum[now] = GG;
  for (int i = 0; i < v[now].size(); i++) {
    int nxt = v[now][i];
    if (nxt == pre) continue;
    dfs(nxt, now);
  }
}
void udt(int G, int p, int val) {
  for (; p < (int)tree[G].size(); p += (p & -p)) tree[G][p] += val;
}
int sum(int G, int p) {
  int ret = 0;
  for (; p; p -= (p & -p)) ret += tree[G][p];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int a, b, i = 1; i <= n - 1; i++) {
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
    ++in[a];
    ++in[b];
    E[i] = {a, b};
  }
  for (int i = 1; i <= n; i++) {
    if (in[i] > 2) {
      root = i;
      break;
    }
  }
  if (root == 0) root = 1;
  tree = vector<vector<int> >((int)v[root].size() + 1);
  tree[0] = vector<int>(2, 0);
  for (int i = 0; i < v[root].size(); i++) {
    int nxt = v[root][i];
    ++GG;
    mx = 0;
    dfs(nxt, root);
    tree[GG] = vector<int>(mx + 1, 0);
  }
  scanf("%d", &m);
  for (int ty, a, b, i = 1; i <= m; i++) {
    scanf("%d", &ty);
    if (ty == 3) {
      scanf("%d %d", &a, &b);
      if (a == b) {
        puts("0");
        continue;
      }
      if (Gnum[a] == Gnum[b]) {
        if (num[a] < num[b]) swap(a, b);
        int key = sum(Gnum[a], num[a]) - sum(Gnum[b], num[b]);
        if (key) {
          puts("-1");
        } else {
          printf("%d\n", num[a] - num[b]);
        }
      } else {
        int key = sum(Gnum[a], num[a]) + sum(Gnum[b], num[b]);
        if (key) {
          puts("-1");
        } else {
          printf("%d\n", num[a] + num[b]);
        }
      }
    } else {
      scanf("%d", &a);
      int lo = E[a].first, hi = E[a].second;
      if (num[lo] < num[hi]) swap(lo, hi);
      if (ty == 1) {
        udt(Gnum[lo], num[lo], -1);
      } else {
        udt(Gnum[lo], num[lo], 1);
      }
    }
  }
}
