#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
  T t = 0;
  char k;
  bool v = 0;
  do (k = getchar()) == '-' && (v = 1);
  while ('0' > k || k > '9');
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
  return v ? -t : t;
}
int s, fa[100005][20], dfn[100005], h[100005], w[100005], rdfn[100005];
vector<int> G[100005];
map<pair<int, int>, int> ma;
void dfs(int n, int f) {
  fa[n][0] = f;
  dfn[n] = ++dfn[0];
  for (int i = 0; fa[n][i + 1] = fa[fa[n][i]][i]; ++i)
    ;
  h[n] = h[f] + 1;
  for (int i = 0; i < G[n].size(); ++i)
    if (G[n][i] ^ f) {
      dfs(G[n][i], n);
      w[ma[make_pair(n, G[n][i])]] = G[n][i];
    }
  rdfn[n] = ++dfn[0];
}
int up(int n, int x) {
  for (int i = 0; x; ++i)
    if (x >> i & 1) {
      n = fa[n][i];
      x ^= 1 << i;
    }
  return n;
}
int lca(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  v = up(v, h[v] - h[u]);
  if (u == v) return u;
  for (int i = 20; i--;)
    if (fa[u][i] ^ fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  return fa[u][0];
}
int b[200005], a[100005];
void add(int x, int v) {
  while (x <= dfn[0]) b[x] += v, x += x & -x;
}
int query(int x) { return x ? b[x] + query(x & x - 1) : 0; }
int main() {
  s = read1<long long>();
  for (int i = 1; i < s; ++i) {
    int u = read1<long long>(), v = read1<long long>();
    ma[make_pair(u, v)] = ma[make_pair(v, u)] = i;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  for (int T = read1<long long>(); T--;) {
    int opt = read1<long long>(), x;
    if (opt == 1)
      if (a[w[x = read1<long long>()]])
        add(dfn[w[x]], -1), add(rdfn[w[x]], 1), a[w[x]] = 0;
    if (opt == 2)
      if (!a[w[x = read1<long long>()]])
        add(dfn[w[x]], 1), add(rdfn[w[x]], -1), a[w[x]] = 1;
    if (opt == 3) {
      int u = read1<long long>(), v = read1<long long>(), w = lca(u, v);
      x = query(dfn[u]) + query(dfn[v]) - 2 * query(dfn[w]);
      if (x)
        puts("-1");
      else
        printf("%d\n", h[u] + h[v] - h[w] * 2);
    }
  }
  return 0;
}
