#include <bits/stdc++.h>
using namespace std;
int N, M, root, type[100005], depth[100005];
vector<int> g[100005];
vector<vector<int> > tree;
pair<int, int> edges[100005];
set<pair<int, int> > s;
void update(int t, int idx, int val) {
  while (idx < tree[t].size()) {
    tree[t][idx] += val;
    idx += (idx & -idx);
  }
}
int read(int t, int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree[t][idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void dfs(int p, int n, int t, int d) {
  bool leaf = true;
  type[n] = t;
  depth[n] = d;
  for (int i = 0; i < g[n].size(); ++i) {
    if (g[n][i] != p) {
      leaf = false;
      dfs(n, g[n][i], t, d + 1);
    }
  }
  if (leaf) {
    tree[t].resize(d + 1);
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; ++i) {
    int n1, n2;
    scanf("%d %d", &n1, &n2);
    g[n1].push_back(n2);
    g[n2].push_back(n1);
    edges[i + 1] = make_pair(n1, n2);
  }
  root = 1;
  for (int i = 1; i <= N; ++i) {
    if (g[i].size() > 2) {
      root = i;
      break;
    }
  }
  depth[root] = 1;
  for (int i = 0; i < g[root].size(); ++i) {
    int child = g[root][i];
    tree.push_back(vector<int>());
    dfs(root, child, i, 2);
  }
  scanf("%d", &M);
  for (int i = 0; i < M; ++i) {
    int T;
    scanf("%d", &T);
    if (T == 1) {
      int id;
      scanf("%d", &id);
      int n1 = edges[id].first, n2 = edges[id].second;
      int t = max(type[n1], type[n2]);
      update(t, depth[n1], -1);
      update(t, depth[n2], -1);
      s.erase(make_pair(n1, n2));
      s.erase(make_pair(n2, n1));
    } else if (T == 2) {
      int id;
      scanf("%d", &id);
      int n1 = edges[id].first, n2 = edges[id].second;
      int t = max(type[n1], type[n2]);
      update(t, depth[n1], 1);
      update(t, depth[n2], 1);
      s.insert(make_pair(n1, n2));
      s.insert(make_pair(n2, n1));
    } else {
      int n1, n2;
      scanf("%d %d", &n1, &n2);
      if (type[n1] == type[n2] || n1 == root || n2 == root) {
        int t = max(type[n1], type[n2]);
        int maxD = max(depth[n1], depth[n2]);
        int minD = min(depth[n1], depth[n2]);
        int dist = maxD - minD;
        int cntBetween = read(t, maxD - 1) - read(t, minD);
        if (cntBetween > 0 || s.find(make_pair(n1, n2)) != s.end()) dist = -1;
        printf("%d\n", dist);
      } else {
        int dist = depth[n1] + depth[n2] - 2;
        int cntBetween1 = read(type[n1], depth[n1] - 1),
            cntBetween2 = read(type[n2], depth[n2] - 1);
        if (cntBetween1 || cntBetween2) dist = -1;
        printf("%d\n", dist);
      }
    }
  }
  return 0;
}
