#include <bits/stdc++.h>
using namespace std;
int n;
int countt[100002];
vector<int> v[100002];
vector<pair<int, int> > vv;
vector<int> root;
int lcc[18][100002];
bool use[100002];
int dep[100002];
inline void dfs(int b, int pre = -1, int h = 0) {
  use[b] = true;
  lcc[0][b] = pre;
  dep[b] = h;
  for (int i = 0; i < v[b].size(); i++) {
    int go = v[b][i];
    if (use[go] == false) {
      dfs(go, b, h + 1);
    }
  }
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) {
    swap(a, b);
  }
  for (int i = 0; i < 18; i++) {
    if (((dep[a] - dep[b]) >> i) & 1) {
      a = lcc[i][a];
    }
  }
  if (a == b) {
    return a;
  }
  for (int i = 18 - 1; i >= 0; i--) {
    if (lcc[i][a] != lcc[i][b]) {
      a = lcc[i][a];
      b = lcc[i][b];
    }
  }
  return lcc[0][a];
}
int belong[100002];
int bel[100002];
vector<vector<int> > g;
vector<vector<int> > bit;
inline void dfs2(int b, int pre) {
  g.back().push_back(b);
  bit.back().push_back(0);
  belong[b] = g.size() - 1;
  bel[b] = g.back().size() - 1;
  for (int i = 0; i < v[b].size(); i++) {
    if (v[b][i] == pre) {
      continue;
    }
    dfs2(v[b][i], b);
  }
}
void add(int i, int j, int x) {
  j++;
  while (j < bit[i].size()) {
    bit[i][j] += x;
    j += j & -j;
  }
}
int sum(int i, int j) {
  int sum = 0;
  j++;
  while (j) {
    sum += bit[i][j];
    j -= j & -j;
  }
  return sum;
}
int flag[100002];
bool ok(int a, int b) {
  if (dep[a] > dep[b]) {
    swap(a, b);
  }
  int aa = belong[b];
  int be = bel[a];
  int en = bel[b];
  int cnt = sum(aa, en) - sum(aa, be);
  return cnt == 0;
}
int dist(int a, int b) { return dep[a] + dep[b] - dep[lca(a, b)] * 2; }
vector<pair<int, int> > ed;
void add_edge(int a, int b, int f = 0) {
  if (dep[a] > dep[b]) {
    swap(a, b);
  }
  int bb = belong[b];
  int bbb = bel[b];
  add(bb, bbb, f);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    countt[a]++;
    countt[b]++;
    v[a].push_back(b);
    v[b].push_back(a);
    ed.push_back(make_pair(a, b));
  }
  for (int i = 0; i < n; i++) {
    vv.push_back(make_pair(countt[i], i));
  }
  sort(vv.begin(), vv.end());
  reverse(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); i++) {
    if (use[vv[i].second] == false) {
      dfs(vv[i].second);
      root.push_back(vv[i].second);
    }
  }
  for (int i = 0; i < root.size(); i++) {
    int a = root[i];
    for (int j = 0; j < v[a].size(); j++) {
      g.push_back(vector<int>());
      g.back().push_back(root[i]);
      bit.push_back(vector<int>());
      bit.back().push_back(0);
      dfs2(v[a][j], root[i]);
      bit.back().push_back(0);
    }
  }
  for (int i = 0; i + 1 < 18; i++) {
    for (int j = 0; j < n; j++) {
      if (lcc[i][j] == -1) {
        lcc[i + 1][j] = -1;
        continue;
      }
      lcc[i + 1][j] = lcc[i][lcc[i][j]];
    }
  }
  memset(flag, -1, sizeof(flag));
  int q;
  scanf("%d", &q);
  while (q--) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int v;
      scanf("%d", &v);
      v--;
      flag[v] *= -1;
      add_edge(ed[v].first, ed[v].second, flag[v]);
      continue;
    }
    if (ty == 2) {
      int v;
      scanf("%d", &v);
      v--;
      flag[v] *= -1;
      add_edge(ed[v].first, ed[v].second, flag[v]);
      continue;
    }
    if (ty == 3) {
      int a, b;
      scanf("%d%d", &a, &b);
      a--;
      b--;
      int lc = lca(a, b);
      int ans = -1;
      if (ok(a, lc) && ok(b, lc)) {
        ans = dist(a, b);
      }
      printf("%d\n", ans);
      continue;
    }
  }
  return 0;
}
