#include <bits/stdc++.h>
using namespace std;
struct segmen_tree {
  int n;
  vector<int> tree;
  segmen_tree(int _) : n(_) {
    int size = 1;
    while (size < n) size *= 2;
    tree.assign(2 * size, 0);
  }
  void upd(int p, int i, int v, int lx, int rx) {
    if (i < lx || i > rx)
      return;
    else if (lx == rx)
      tree[p] = v;
    else {
      int mid = (lx + rx) / 2;
      if (i <= mid)
        upd(p << 1, i, v, lx, mid);
      else
        upd(p << 1 | 1, i, v, mid + 1, rx);
      tree[p] = tree[p << 1] + tree[p << 1 | 1];
    }
  }
  int qry(int p, int l, int r, int lx, int rx) {
    int mid = (lx + rx) / 2;
    if (rx < l || lx > r)
      return 0;
    else if (lx >= l && rx <= r)
      return tree[p];
    else
      return qry(p << 1, l, r, lx, mid) + qry(p << 1 | 1, l, r, mid + 1, rx);
  }
  void upd(int i, int v) {
    i++;
    upd(1, i, v, 1, n);
  }
  int qry(int l, int r) {
    l++, r++;
    return qry(1, l, r, 1, n);
  }
};
const int N = 100000;
int n, m, pos[N], level[N], par[N], head[N], cnt, sz[N];
int req[N];
segmen_tree st(N);
vector<pair<int, int>> adj[N];
void dfs(int x, int pr, int lvl) {
  par[x] = pr, level[x] = lvl, sz[x] = 1;
  for (auto e : adj[x])
    if (e.first != pr) {
      dfs(e.first, x, lvl + 1);
      sz[x] += sz[e.first];
      req[e.second] = e.first;
    }
}
void decompose(int x, int pr, bool not_head) {
  pos[x] = cnt++;
  if (not_head)
    head[x] = head[pr];
  else
    head[x] = x;
  int mx = -1, mxi = -1;
  for (auto e : adj[x])
    if (e.first != pr && sz[e.first] > mx) mx = sz[e.first], mxi = e.first;
  if (mxi != -1) decompose(mxi, x, true);
  for (auto e : adj[x])
    if (e.first != pr && e.first != mxi) decompose(e.first, x, false);
}
void upd(int i, int v) { st.upd(pos[req[i]], v); }
int qry(int x, int y) {
  int dist = 0, res = 0;
  while (head[x] != head[y]) {
    if (level[head[x]] < level[head[y]]) swap(x, y);
    dist += 1 + pos[x] - pos[head[x]];
    res += st.qry(pos[head[x]], pos[x]);
    x = par[head[x]];
  }
  if (level[x] < level[y]) swap(x, y);
  if (x != y) res += st.qry(pos[y] + 1, pos[x]);
  dist += pos[x] - pos[y];
  if (res == dist)
    return dist;
  else
    return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].emplace_back(y, i);
    adj[y].emplace_back(x, i);
  }
  dfs(0, -1, 0);
  decompose(0, -1, false);
  cin >> m;
  for (int i = 0; i < n - 1; i++) upd(i, 1);
  while (m--) {
    int t;
    cin >> t;
    if (t == 1) {
      int id;
      cin >> id;
      id--;
      upd(id, 1);
    } else if (t == 2) {
      int id;
      cin >> id;
      id--;
      upd(id, 0);
    } else {
      int a, b;
      cin >> a >> b;
      a--, b--;
      cout << qry(a, b) << '\n';
    }
  }
}
