#include <bits/stdc++.h>
using namespace std;
struct TNode {
  int par;
  int depth;
  int sz;
  int pos_segbase;
  int heavy;
} node[200005];
int T[4 * 200005];
int bar[200005], heavy[200005];
vector<int> adj[200005];
int av;
int dfs(int cur, int pre, int dpt) {
  node[cur].par = pre;
  node[cur].depth = dpt;
  node[cur].heavy = -1;
  int s = 1, h = 0;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] != pre) {
      int c = dfs(adj[cur][i], cur, dpt + 1);
      if (c > h) {
        h = c;
        node[cur].heavy = i;
      }
      s += c;
    }
  }
  return node[cur].sz = s;
}
int chainNo, chainHead[200005], chainInd[200005];
void hld(int cur, int pre) {
  if (chainHead[chainNo] == -1) {
    chainHead[chainNo] = cur;
  }
  chainInd[cur] = chainNo;
  node[cur].pos_segbase = av++;
  int ind = node[cur].heavy;
  if (ind >= 0) {
    hld(adj[cur][ind], cur);
  }
  for (int i = 0; i < adj[cur].size(); i++) {
    if (ind != i && adj[cur][i] != pre) {
      chainNo++;
      hld(adj[cur][i], cur);
    }
  }
}
void up(int p, int lw, int hg, int x, int vl) {
  if (lw == hg) {
    T[p] = vl;
    return;
  }
  int m = (lw + hg) / 2;
  if (x <= m)
    up(2 * p, lw, m, x, vl);
  else
    up(2 * p + 1, m + 1, hg, x, vl);
  T[p] = T[2 * p] + T[2 * p + 1];
}
int RMQ(int p, int lw, int hg, int x, int y) {
  if (x > hg || y < lw) {
    return 0;
  }
  if (lw >= x && hg <= y) {
    return T[p];
  }
  int md = (lw + hg) / 2;
  return RMQ(2 * p, lw, md, x, y) + RMQ(2 * p + 1, md + 1, hg, x, y);
}
pair<int, int> chain_up(int u, int v, int n) {
  int chain_u, chain_v, ans = 0, tt = 0;
  while (true) {
    chain_u = chainInd[u];
    chain_v = chainInd[v];
    if (chain_u == chain_v) {
      if (node[v].depth > node[u].depth) {
        swap(u, v);
      }
      tt += abs(node[v].pos_segbase - node[u].pos_segbase);
      ans += RMQ(1, 1, n, node[v].pos_segbase, node[u].pos_segbase);
      ans -= RMQ(1, 1, n, node[v].pos_segbase, node[v].pos_segbase);
      break;
    } else {
      if (chain_u < chain_v) {
        ans += RMQ(1, 1, n, node[chainHead[chain_v]].pos_segbase,
                   node[v].pos_segbase);
        tt +=
            abs(node[chainHead[chain_v]].pos_segbase - node[v].pos_segbase) + 1;
        v = node[chainHead[chain_v]].par;
      } else {
        ans += RMQ(1, 1, n, node[chainHead[chain_u]].pos_segbase,
                   node[u].pos_segbase);
        tt +=
            abs(node[chainHead[chain_u]].pos_segbase - node[u].pos_segbase) + 1;
        u = node[chainHead[chain_u]].par;
      }
    }
  }
  return {tt, ans};
}
void maxEdge(int u, int v, int n) {
  pair<int, int> ret = chain_up(u, v, n);
  if (ret.first > ret.second)
    cout << -1 << endl;
  else
    cout << ret.second << endl;
}
void Set(int n) {
  for (int i = 0; i <= n; i++) {
    chainHead[i] = -1;
    chainInd[i] = 0;
    adj[i].clear();
  }
}
vector<pair<int, int> > edge;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc, i, j, n, k, x, y, q;
  cin >> n;
  Set(n);
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    edge.push_back({x, y});
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 0, 0);
  chainNo = 0;
  av = 1;
  hld(1, 0);
  for (i = 1; i <= n; i++) up(1, 1, n, node[i].pos_segbase, 1);
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 3) {
      cin >> x >> y;
      maxEdge(x, y, n);
    } else if (t == 1) {
      cin >> x;
      x--;
      pair<int, int> ret = edge[x];
      if (node[ret.second].par == ret.first) swap(ret.first, ret.second);
      up(1, 1, n, node[ret.first].pos_segbase, 1);
    } else {
      cin >> x;
      x--;
      pair<int, int> ret = edge[x];
      if (node[ret.second].par == ret.first) swap(ret.first, ret.second);
      up(1, 1, n, node[ret.first].pos_segbase, 0);
    }
  }
  return 0;
}
