#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210000;
int n, m;
int tot, front[MAXN], to[MAXN], nxt[MAXN], X[MAXN * 3], Y[3 * MAXN];
int fa[MAXN][20], dep[MAXN], siz[MAXN], dfn[MAXN], b[MAXN], dfn_clock;
void init(int u, int v) {
  to[++tot] = v;
  nxt[tot] = front[u];
  front[u] = tot;
}
void dfs(int u, int father) {
  fa[u][0] = father;
  dep[u] = dep[father] + 1;
  siz[u] = 1;
  dfn[u] = ++dfn_clock;
  b[dfn_clock] = u;
  for (int i = front[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == father) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
}
int flag[MAXN * 4], sum[MAXN * 4];
void build(int root, int l, int r) {
  if (l == r) {
    sum[root] = dep[b[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(root * 2, l, mid);
  build(root * 2 + 1, mid + 1, r);
  sum[root] = sum[root * 2] + sum[root * 2 + 1];
}
void pushdown(int root, int l, int r) {
  int mid = (l + r) >> 1;
  sum[root * 2] += flag[root] * (mid - l + 1);
  flag[root * 2] += flag[root];
  sum[root * 2 + 1] += flag[root] * (r - mid);
  flag[root * 2 + 1] += flag[root];
  flag[root] = 0;
}
void add(int root, int l, int r, int xl, int xr, int t) {
  if (xl > xr) return;
  if (l == xl && r == xr) {
    sum[root] += t * (r - l + 1);
    flag[root] += t;
    return;
  }
  if (flag[root]) pushdown(root, l, r);
  int mid = (l + r) >> 1;
  if (xr <= mid)
    add(root * 2, l, mid, xl, xr, t);
  else if (xl > mid)
    add(root * 2 + 1, mid + 1, r, xl, xr, t);
  else
    add(root * 2, l, mid, xl, mid, t),
        add(root * 2 + 1, mid + 1, r, mid + 1, xr, t);
  sum[root] = sum[root * 2] + sum[root * 2 + 1];
}
int qry(int root, int l, int r, int t) {
  if (l == r) return sum[root];
  int mid = (l + r) >> 1;
  if (flag[root]) pushdown(root, l, r);
  if (t <= mid)
    return qry(root * 2, l, mid, t);
  else
    return qry(root * 2 + 1, mid + 1, r, t);
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &X[i], &Y[i]);
    init(X[i], Y[i]);
    init(Y[i], X[i]);
  }
  dfs(1, 0);
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  build(1, 1, n);
  int m, opt, x;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d", &x);
      int u = X[x];
      if (dep[u] < dep[Y[x]]) u = Y[x];
      add(1, 1, n, dfn[u], dfn[u] + siz[u] - 1, 1);
    }
    if (opt == 2) {
      scanf("%d", &x);
      int u = X[x];
      if (dep[u] < dep[Y[x]]) u = Y[x];
      add(1, 1, n, dfn[u], dfn[u] + siz[u] - 1, -1);
    }
    if (opt == 3) {
      int u, v, t;
      scanf("%d%d", &u, &v);
      t = lca(u, v);
      int t1 = qry(1, 1, n, dfn[u]), t2 = qry(1, 1, n, dfn[t]);
      if (dep[u] - dep[t] != t1 - t2) {
        printf("-1\n");
        continue;
      }
      t1 = qry(1, 1, n, dfn[v]), t2 = qry(1, 1, n, dfn[t]);
      if (dep[v] - dep[t] != t1 - t2) {
        printf("-1\n");
        continue;
      }
      printf("%d\n", dep[u] + dep[v] - dep[t] * 2);
    }
  }
  return 0;
}
