#include <bits/stdc++.h>
using namespace std;
int n, m, x[100005 * 3], y[100005 * 3], f[100005], d[100005], siz[100005],
    son[100005], top[100005], dfn[100005], w[100005], cnt, dp[100005][20];
vector<int> G[100005];
struct node {
  int l, r, s, flag;
} tree[100005 * 4];
void pushsum(int Index) {
  tree[Index].s = tree[Index * 2].s + tree[Index * 2 + 1].s;
}
void build(int Index, int l, int r) {
  tree[Index].l = l;
  tree[Index].r = r;
  tree[Index].flag = 0;
  if (l == r) {
    tree[Index].s = w[l];
    return;
  }
  int mid = l + r >> 1;
  build(Index * 2, l, mid);
  build(Index * 2 + 1, mid + 1, r);
  pushsum(Index);
}
void pushdown(int Index) {
  tree[Index * 2].flag += tree[Index].flag;
  tree[Index * 2].s +=
      tree[Index].flag * (tree[Index * 2].r - tree[Index * 2].l + 1);
  tree[Index * 2 + 1].flag += tree[Index].flag;
  tree[Index * 2 + 1].s +=
      tree[Index].flag * (tree[Index * 2 + 1].r - tree[Index * 2 + 1].l + 1);
  tree[Index].flag = 0;
}
void update(int Index, int l, int r, int val) {
  if (tree[Index].l >= l && tree[Index].r <= r) {
    tree[Index].flag += val;
    tree[Index].s += val * (tree[Index].r - tree[Index].l + 1);
    return;
  }
  pushdown(Index);
  int mid = tree[Index].l + tree[Index].r >> 1;
  if (l <= mid) update(Index * 2, l, r, val);
  if (r > mid) update(Index * 2 + 1, l, r, val);
  pushsum(Index);
}
int query(int Index, int l, int r) {
  if (tree[Index].l >= l && tree[Index].r <= r) return tree[Index].s;
  pushdown(Index);
  int mid = tree[Index].l + tree[Index].r >> 1, ans = 0;
  if (l <= mid) ans += query(Index * 2, l, r);
  if (r > mid) ans += query(Index * 2 + 1, l, r);
  return ans;
}
void dfs1(int x, int fa) {
  f[x] = fa;
  siz[x] = 1;
  d[x] = d[fa] + 1;
  int maxn = -1;
  for (int i = 0; i < G[x].size(); i++) {
    int tmp = G[x][i];
    if (tmp != fa) {
      dfs1(tmp, x);
      if (siz[tmp] > maxn) maxn = siz[tmp], son[x] = tmp;
      siz[x] += siz[tmp];
      dp[tmp][0] = x;
    }
  }
}
void dfs2(int x, int fa) {
  cnt++;
  top[x] = fa;
  dfn[x] = cnt;
  w[cnt] = 0;
  if (son[x]) dfs2(son[x], fa);
  for (int i = 0; i < G[x].size(); i++) {
    int tmp = G[x][i];
    if (tmp != f[x] && tmp != son[x]) dfs2(tmp, tmp);
  }
}
int get_sum(int x, int y) {
  int sum = 0;
  while (top[x] != top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    sum += query(1, dfn[top[x]], dfn[x]);
    x = f[top[x]];
  }
  if (dfn[x] > dfn[y])
    sum += query(1, dfn[y], dfn[x]);
  else
    sum += query(1, dfn[x], dfn[y]);
  return sum;
}
void Add(int x, int y, int val) {
  while (top[x] != top[y]) {
    if (d[top[x]] < d[top[y]]) swap(x, y);
    update(1, dfn[top[x]], dfn[x], val);
    x = f[top[x]];
  }
  if (d[x] > d[y]) swap(x, y);
  update(1, dfn[x], dfn[y], val);
}
void prepare() {
  dp[1][0] = 0;
  for (int j = 1; j < 20; j++) {
    for (int i = 1; i <= n; i++) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }
}
void add(int &x, int maxdep) {
  for (int i = 19; i >= 0; i--)
    if (d[dp[x][i]] >= maxdep) x = dp[x][i];
}
int Doubly(int x, int y) {
  if (d[x] > d[y]) add(x, d[y]);
  if (d[x] < d[y]) add(y, d[x]);
  if (x == y) return x;
  for (int i = 19; i >= 0; i--) {
    if (dp[x][i] != dp[y][i]) x = dp[x][i], y = dp[y][i];
  }
  return dp[x][0];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    G[x[i]].push_back(y[i]);
    G[y[i]].push_back(x[i]);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  build(1, 1, n);
  prepare();
  scanf("%d", &m);
  while (m--) {
    int flag, u, v;
    scanf("%d", &flag);
    if (flag == 3) {
      scanf("%d %d", &u, &v);
      int lca = Doubly(u, v);
      if (get_sum(u, v) - query(1, dfn[lca], dfn[lca]) > 0)
        printf("-1\n");
      else
        printf("%d\n", d[u] + d[v] - d[lca] * 2);
    } else {
      scanf("%d", &u);
      if (dp[x[u]][0] == y[u])
        u = x[u];
      else
        u = y[u];
      if (flag == 1) {
        if (query(1, dfn[u], dfn[u]) == 1) update(1, dfn[u], dfn[u], -1);
      } else {
        if (query(1, dfn[u], dfn[u]) == 0) update(1, dfn[u], dfn[u], 1);
      }
    }
  }
  return 0;
}
