#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
vector<int> gr[MAXN];
int depth[MAXN], parent[MAXN], treesz[MAXN];
int chain[MAXN], chainpos[MAXN], chainleader[MAXN];
int N, cur_chain, pos;
int tree[4 * MAXN];
int edge[MAXN];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(node * 2, l, mid);
  build(node * 2 + 1, mid + 1, r);
  tree[node] = tree[2 * node + 1] + tree[2 * node];
}
void update(int node, int l, int r, int x, int val) {
  if (l > r) return;
  if (l == r) {
    tree[node] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(2 * node, l, mid, x, val);
  else
    update(2 * node + 1, mid + 1, r, x, val);
  tree[node] = tree[2 * node + 1] + tree[2 * node];
}
int query(int node, int l, int r, int x, int y) {
  if (l > r || l > y || r < x || x > y) return 0;
  if (x <= l && r <= y) {
    return tree[node];
  }
  int mid = (l + r) >> 1;
  return query(2 * node, l, mid, x, y) + query(2 * node + 1, mid + 1, r, x, y);
}
void explore(int u) {
  int v;
  treesz[u] = 1;
  for (size_t i = 0, sz = gr[u].size(); i < sz; ++i) {
    v = gr[u][i];
    if (parent[v] == -1) {
      parent[v] = u;
      depth[v] = depth[u] + 1;
      explore(v);
      treesz[u] += treesz[v];
    }
  }
}
void decompose(int u, bool light = true) {
  if (light) {
    ++cur_chain;
    chainleader[cur_chain] = u;
  }
  chain[u] = cur_chain;
  chainpos[u] = pos++;
  int v, ind = -1, mx = -1, c;
  for (size_t i = 0, sz = gr[u].size(); i < sz; i++) {
    v = gr[u][i];
    if (parent[v] == u && (mx == -1 || treesz[mx] < treesz[v]))
      mx = v, ind = i, c = gr[u][i];
  }
  if (mx != -1) {
    decompose(mx, false);
  }
  for (size_t i = 0, sz = gr[u].size(); i < sz; ++i) {
    v = gr[u][i];
    if (parent[v] == u && v != mx) {
      decompose(v);
    }
  }
}
int lca(int u, int v) {
  while (chain[u] != chain[v]) {
    if (depth[chainleader[chain[u]]] < depth[chainleader[chain[v]]])
      v = parent[chainleader[chain[v]]];
    else
      u = parent[chainleader[chain[u]]];
  }
  if (depth[u] < depth[v]) return u;
  return v;
}
int query_hld(int u, int v) {
  int ans = 0;
  int uchain, vchain;
  vchain = chain[v];
  int sz = 0;
  while (1) {
    uchain = chain[u];
    if (uchain == vchain) {
      if (v != u) ans += query(1, 0, pos - 1, chainpos[v] + 1, chainpos[u]);
      break;
    } else {
      ans += query(1, 0, pos - 1, chainpos[chainleader[chain[u]]] + 1,
                   chainpos[u]);
      ans += query(1, 0, pos - 1, chainpos[chainleader[chain[u]]],
                   chainpos[chainleader[chain[u]]]);
      u = parent[chainleader[chain[u]]];
    }
  }
  return ans;
}
int query_up(int u, int v) {
  int LCA = lca(u, v);
  int size_chain = depth[u] - depth[LCA];
  int size_chain1 = depth[v] - depth[LCA];
  int ans = query_hld(u, LCA);
  int ans1 = query_hld(v, LCA);
  int ans2 = INT_MAX;
  if ((ans1 + ans) == (size_chain + size_chain1)) ans2 = ans1 + ans;
  return ans2;
}
vector<pair<int, int> > arestas;
int main() {
  ios_base::sync_with_stdio(0);
  memset(depth, 0, sizeof(depth));
  memset(treesz, 0, sizeof(treesz));
  memset(parent, -1, sizeof(parent));
  cur_chain = -1;
  pos = 0;
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b, c;
    cin >> a >> b;
    arestas.push_back(make_pair(a, b));
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  parent[1] = 0;
  explore(1);
  decompose(1, 0);
  build(1, 0, pos - 1);
  int m;
  cin >> m;
  while (m--) {
    int a, b, op;
    cin >> op;
    if (op == 1) {
      cin >> a;
      int lo = arestas[a - 1].first;
      int hi = arestas[a - 1].second;
      if (chainpos[lo] < chainpos[hi]) {
        update(1, 0, pos - 1, chainpos[hi], 1);
      } else {
        update(1, 0, pos - 1, chainpos[lo], 1);
      }
    } else if (op == 2) {
      cin >> a;
      int lo = arestas[a - 1].first;
      int hi = arestas[a - 1].second;
      if (chainpos[lo] < chainpos[hi]) {
        update(1, 0, pos - 1, chainpos[hi], 0);
      } else {
        update(1, 0, pos - 1, chainpos[lo], 0);
      }
    } else {
      cin >> a >> b;
      int ans = query_up(a, b);
      if (ans == INT_MAX)
        cout << "-1\n";
      else
        cout << ans << '\n';
    }
  }
  return 0;
}
