#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int INF = 2000000010;
int n, m, ln, st[MAXN];
int aim[MAXN], link[MAXN];
int s, deg[MAXN];
bool rch[MAXN];
int iset[MAXN], idx[MAXN];
struct Edge {
  int u, v;
} e[MAXN];
struct BiTree {
  int tn;
  vector<long long> v;
  void init() {
    for (int i = 0; i <= tn; i++) v.push_back(0);
  }
  void upd(int p, long long x) {
    for (; p <= tn; p += (p & (-p))) v[p] += x;
  }
  long long sum(int p) {
    long long ret = 0;
    for (; p > 0; p -= (p & (-p))) ret += v[p];
    return ret;
  }
} bt[MAXN];
void inEdge(int u, int v) {
  aim[ln] = v;
  link[ln] = st[u];
  st[u] = ln++;
}
void markSet(int u, int mySet, int &idxN) {
  iset[u] = mySet;
  idx[u] = ++idxN;
  for (int j = st[u]; j != -1; j = link[j]) {
    int v = aim[j];
    if (iset[v] == -1) markSet(v, mySet, idxN);
  }
}
int main() {
  scanf("%d", &n);
  memset(st, 255, sizeof(st));
  ln = 0;
  memset(deg, 0, sizeof(deg));
  s = 0;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &e[i].u, &e[i].v);
    e[i].u--;
    e[i].v--;
    inEdge(e[i].u, e[i].v);
    inEdge(e[i].v, e[i].u);
    if (++deg[e[i].u] > 2) s = e[i].u;
    if (++deg[e[i].v] > 2) s = e[i].v;
  }
  memset(iset, 255, sizeof(iset));
  iset[s] = s;
  idx[s] = 1;
  bt[s].tn = 1;
  bt[s].init();
  for (int j = st[s]; j != -1; j = link[j]) {
    int v = aim[j];
    bt[v].tn = 0;
    markSet(v, v, bt[v].tn);
    bt[v].init();
  }
  for (int u = 0; u < n; u++) bt[iset[u]].upd(idx[u], 1);
  memset(rch, true, sizeof(rch));
  for (scanf("%d", &m); m; m--) {
    int c;
    scanf("%d", &c);
    if (c < 3) {
      int k;
      scanf("%d", &k);
      k--;
      int u = e[k].u, v = e[k].v;
      if (v == s) swap(u, v);
      if (u == s)
        rch[v] = !rch[v];
      else {
        if (idx[u] < idx[v]) swap(u, v);
        if (c == 1)
          bt[iset[u]].upd(idx[u], -INF);
        else
          bt[iset[u]].upd(idx[u], INF);
      }
    } else {
      int u, v;
      scanf("%d %d", &u, &v);
      u--;
      v--;
      if (v == s) swap(u, v);
      long long du = bt[iset[u]].sum(idx[u]);
      long long dv = bt[iset[v]].sum(idx[v]);
      long long cost;
      if (u == v)
        cost = 0;
      else if (u == s) {
        if (rch[iset[v]])
          cost = dv;
        else
          cost = -1;
      } else if (iset[u] == iset[v])
        cost = abs(du - dv);
      else {
        if (rch[iset[u]] && rch[iset[v]])
          cost = du + dv;
        else
          cost = -1;
      }
      if (cost > INF) cost = -1;
      printf("%d\n", (int)cost);
    }
  }
  return 0;
}
