#include <bits/stdc++.h>
using namespace std;
const int maxn = 120000;
struct node {
  int d, a, b;
  node *next;
} * lin[maxn], ss[maxn];
int f[maxn], w[maxn], d[maxn], own[maxn];
int s[maxn], m[maxn];
int L;
void ins(int a, int b) {
  node *p = new node;
  p->d = b;
  p->next = lin[a];
  lin[a] = p;
}
void build(int t, int fa) {
  node *p = lin[t];
  f[t] = fa;
  if (fa == -1)
    d[t] = 0;
  else
    d[t] = d[fa] + 1;
  while (p != NULL) {
    if (p->d != fa) {
      if (++s[own[t]] < L) own[p->d] = own[t];
      build(p->d, t);
    }
    p = p->next;
  }
}
void dfs(int t, int fa) {
  node *p = lin[t];
  if (fa != -1)
    s[t] = s[fa] + w[t], m[t] = min(w[t], m[fa]);
  else
    s[t] = w[t], m[t] = w[t];
  while (p != NULL) {
    if (p->d != fa && own[p->d] == own[t]) {
      dfs(p->d, t);
    }
    p = p->next;
  }
}
void calc(int a, int b, int &M, int &S) {
  S = 0;
  M = 2;
  while (a != b) {
    if (own[a] == own[b]) {
      if (d[a] < d[b]) swap(a, b);
      M = min(w[a], M);
      S += w[a];
      a = f[a];
    } else {
      if (d[own[a]] < d[own[b]]) swap(a, b);
      M = min(m[a], M);
      S += s[a];
      a = f[own[a]];
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  L = int(sqrt(n)) / 2 * 1;
  for (int i = 1; i <= n; i++) lin[i] = NULL, own[i] = i;
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    scanf("%d%d", &ss[i].a, &ss[i].b);
    ins(ss[i].a, ss[i].b);
    ins(ss[i].b, ss[i].a);
  }
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; i++) w[i] = 1;
  build(rand() % n + 1, -1);
  for (int i = 1; i <= n; i++)
    if (own[i] == i) dfs(i, -1);
  int r;
  scanf("%d", &r);
  for (int i = 1; i <= r; i++) {
    int c;
    scanf("%d", &c);
    if (c == 1) {
      int d;
      scanf("%d", &d);
      int a = ss[d].b;
      if (f[ss[d].a] == ss[d].b) a = ss[d].a;
      w[a] = 1;
      if (own[a] == a)
        dfs(a, -1);
      else
        dfs(a, f[a]);
    }
    if (c == 2) {
      int d;
      scanf("%d", &d);
      int a = ss[d].b;
      if (f[ss[d].a] == ss[d].b) a = ss[d].a;
      w[a] = 0;
      if (own[a] == a)
        dfs(a, -1);
      else
        dfs(a, f[a]);
    }
    if (c == 3) {
      int a, b;
      scanf("%d%d", &a, &b);
      int M, s;
      calc(a, b, M, s);
      if (M == 0)
        printf("-1\n");
      else
        printf("%d\n", s);
    }
  }
  return 0;
}
