#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
int u[300005], v[300005], cl[300005];
struct it {
  int v, w;
  it() { v = w = 0; }
  it(int V, int W) {
    v = V;
    w = W;
  }
};
vector<int> g[300005];
int d[300005], dfn[300005], rr[300005], cnt;
int f[300005][20];
int c[300005];
void addt(int x, int y) {
  while (x <= n) c[x] += y, x += ((-x) & (x));
}
int sum(int x) {
  int as = 0;
  while (x > 0) as += c[x], x -= ((-x) & (x));
  return as;
}
void dfs(int x, int fa) {
  d[x] = d[fa] + 1;
  dfn[x] = ++cnt;
  f[x][0] = fa;
  for (int i = 1; i <= 18; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] != fa) {
      dfs(g[x][i], x);
    }
  }
  rr[x] = cnt;
  return;
}
int lca(int a, int b) {
  if (d[b] > d[a]) swap(a, b);
  if (d[a] > d[b]) {
    for (int i = 18; i >= 0; i--) {
      if (d[f[a][i]] >= d[b]) {
        a = f[a][i];
      }
    }
  }
  if (a == b) return a;
  for (int i = 18; i >= 0; i--) {
    if (f[a][i] != f[b][i]) {
      a = f[a][i], b = f[b][i];
    }
  }
  return f[a][0];
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    s = u[i] = read();
    o = v[i] = read();
    g[s].push_back(o);
    g[o].push_back(s);
  }
  dfs(1, 1);
  m = read();
  for (int i = 1; i <= m; i++) {
    k = read();
    if (k == 1) {
      s = read();
      int p = (d[u[s]] > d[v[s]] ? u[s] : v[s]);
      if (cl[s]) addt(dfn[p], -1), addt(rr[p] + 1, 1), cl[s] = 0;
    } else if (k == 2) {
      s = read();
      int p = (d[u[s]] > d[v[s]] ? u[s] : v[s]);
      if (!cl[s]) addt(dfn[p], 1), addt(rr[p] + 1, -1), cl[s] = 1;
    } else {
      s = read();
      o = read();
      int lc = lca(s, o);
      if (sum(dfn[s]) + sum(dfn[o]) - 2 * sum(dfn[lc])) {
        printf("-1\n");
      } else
        printf("%d\n", d[s] + d[o] - d[lc] * 2);
    }
  }
  return 0;
}
