#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e5 + 10;
int n, root, q;
vector<int> v[maxi];
map<int, int> bit[maxi];
pair<int, int> krak[maxi];
map<pair<int, int>, pair<int, int>> mp;
int level, cnt;
int x[maxi], y[maxi];
void dfs(int pred, int x, int cnt) {
  if (x != root) {
    level++;
    krak[x] = {cnt, level};
  }
  mp[{x, pred}] = {level, cnt};
  mp[{pred, x}] = {level, cnt};
  for (int i : v[x])
    if (i != pred) {
      dfs(x, i, cnt);
    }
}
void update(int poz, int x, int val) {
  for (int i = poz; i < maxi; i += i & (-i)) bit[x][i] += val;
}
int get(int poz, int x) {
  int ans = 0;
  for (int i = poz; i > 0; i -= i & (-i)) ans += bit[x][i];
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    v[x[i]].push_back(y[i]);
    v[y[i]].push_back(x[i]);
  }
  int root = 1;
  for (int i = 2; i <= n; i++)
    if (v[root].size() < v[i].size()) root = i;
  for (int i : v[root]) {
    cnt++;
    level = 0;
    dfs(root, i, cnt);
    for (int j = 1; j <= level; j++) update(j, cnt, 1);
  }
  cin >> q;
  while (q--) {
    int tip;
    scanf("%d", &tip);
    if (tip == 1) {
      int id;
      scanf("%d", &id);
      pair<int, int> node = mp[{x[id], y[id]}];
      update(node.first, node.second, 1);
    }
    if (tip == 2) {
      int id;
      scanf("%d", &id);
      pair<int, int> node = mp[{x[id], y[id]}];
      update(node.first, node.second, -1);
    }
    if (tip == 3) {
      int snode, enode;
      scanf("%d%d", &snode, &enode);
      if (snode == root && enode == root)
        printf("0\n");
      else if (snode == root || enode == root) {
        int len = max(krak[snode].second, krak[enode].second);
        int kk = 0;
        if (snode != root)
          kk = krak[snode].first;
        else
          kk = krak[enode].first;
        if (get(len, kk) == len)
          printf("%d\n", len);
        else
          printf("-1\n");
      } else if (krak[snode].first == krak[enode].first) {
        int len = max(krak[snode].second, krak[enode].second) -
                  min(krak[snode].second, krak[enode].second);
        int kk = krak[snode].first;
        if (abs(get(krak[snode].second, kk) - get(krak[enode].second, kk)) ==
            len)
          printf("%d\n", len);
        else
          printf("-1\n");
      } else {
        int len = krak[snode].second + krak[enode].second;
        if (get(krak[snode].second, krak[snode].first) +
                get(krak[enode].second, krak[enode].first) ==
            len)
          printf("%d\n", len);
        else
          printf("-1\n");
      }
    }
  }
  return 0;
}
