#include <bits/stdc++.h>
using namespace std;
int root;
int wi = 0;
int n;
int mml = 0;
void dfs(int v, int cur, int w, vector<int> edge[], int vis[], int d[]) {
  d[v] = cur;
  cur++;
  vis[v] = w;
  for (int i = 0; i < (int)edge[v].size(); i++) {
    if (!vis[edge[v][i]]) {
      dfs(edge[v][i], cur, w, edge, vis, d);
      if (v == root) w++;
    }
  }
  wi = max(wi, w);
  mml = max(mml, cur);
}
struct bt {
  vector<int> arr;
  bt() { arr.resize(mml + 2); }
  void update(int ind, int val) {
    while (ind <= mml) {
      arr[ind] += val;
      ind += (ind & -ind);
    }
  }
  int query(int ind) {
    int sum = 0;
    while (ind > 0) {
      sum += arr[ind];
      ind -= (ind & -ind);
    }
    return sum;
  }
};
int main() {
  int u, v;
  scanf("%d", &n);
  ;
  vector<int> edge[n + 1];
  int vis[n + 1];
  int d[n + 1];
  memset(vis, 0, sizeof(vis));
  memset(d, 0, sizeof(d));
  pair<int, int> ed[n];
  int maxedge = 0;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &u);
    ;
    scanf("%d", &v);
    ;
    edge[u].push_back(v);
    edge[v].push_back(u);
    ed[i + 1] = make_pair(u, v);
    if (maxedge < (int)edge[u].size()) {
      maxedge = edge[u].size();
      root = u;
    }
    if (maxedge < (int)edge[v].size()) {
      maxedge = edge[v].size();
      root = v;
    }
  }
  dfs(root, 0, 1, edge, vis, d);
  vis[root] = 0;
  bt bit[wi + 1];
  int m, type, a, b;
  int path;
  int edgenum;
  scanf("%d", &m);
  ;
  while (m--) {
    scanf("%d", &type);
    ;
    scanf("%d", &a);
    ;
    if (type != 3) {
      edgenum = max(d[ed[a].second], d[ed[a].first]);
      path = max(vis[ed[a].second], vis[ed[a].first]);
    }
    if (type == 1) {
      bit[path].update(edgenum, 1);
    } else if (type == 2) {
      bit[path].update(edgenum, -1);
    } else {
      scanf("%d", &b);
      ;
      if (a == b) {
        printf("%d\n", 0);
        ;
        continue;
      }
      if (vis[a] == vis[b]) {
        if (bit[vis[b]].query(d[b]) == bit[vis[a]].query(d[a])) {
          printf("%d\n", abs(d[a] - d[b]));
          ;
          continue;
        }
      }
      if (a != root && bit[vis[a]].query(d[a]) < 0) {
        printf("%d\n", -1);
        ;
        continue;
      }
      if (b != root && bit[vis[b]].query(d[b]) < 0) {
        printf("%d\n", -1);
        ;
        continue;
      }
      printf("%d\n", d[a] + d[b]);
      ;
    }
  }
}
