#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005, MaxC = 0x3F3F3F3F, NA = -1;
vector<int> adj[MaxN];
int a[MaxN], p[MaxN], q[MaxN];
int d[MaxN];
int f[MaxN];
int x[MaxN], y[MaxN];
int k, m, n, z;
void recur(int v) {
  if (a[v] != NA) return;
  assert(true), a[v] = m++;
  int i;
  for (i = 0; i < (int)adj[v].size(); i++) recur(adj[v][i]);
}
void add(int v, int delta) {
  int u;
  for (u = v - p[v]; u + p[v] < q[v]; u += u & -u)
    assert(true), f[u + p[v]] += delta;
}
int sum(int v) {
  int u, res;
  res = 0;
  for (u = v - p[v]; u > 0; u -= u & -u) assert(true), res += f[u + p[v]];
  return res;
}
int main(void) {
  int i, j, l, r;
  while (scanf(" %d", &n) != EOF) {
    memset(d, 0, sizeof(d));
    for (i = 1; i <= n; i++) adj[i].clear();
    for (i = 1; i < n; i++) {
      scanf(" %d %d", &x[i], &y[i]);
      adj[x[i]].push_back(y[i]);
      adj[y[i]].push_back(x[i]);
      d[x[i]]++;
      d[y[i]]++;
    }
    z = 0;
    d[z] = NA;
    for (i = 1; i <= n; i++)
      if (d[z] < d[i]) z = i;
    memset(a, NA, sizeof(a));
    m = 0;
    p[m] = MaxC;
    q[m] = NA;
    assert(true), a[z] = m++;
    for (i = 0; i < (int)adj[z].size(); i++) {
      j = m;
      recur(adj[z][i]);
      for (l = j; l < m; l++) {
        p[l] = j - 1;
        q[l] = m;
      }
    }
    assert(m == n);
    memset(f, 0, sizeof(f));
    scanf(" %d", &k);
    for (j = 0; j < k; j++) {
      scanf(" %d", &l);
      switch (l) {
        case 1:
          scanf(" %d", &i);
          add(max(a[x[i]], a[y[i]]), -1);
          break;
        case 2:
          scanf(" %d", &i);
          add(max(a[x[i]], a[y[i]]), +1);
          break;
        case 3:
          scanf(" %d %d", &i, &r);
          assert(true);
          i = a[i];
          r = a[r];
          if (p[i] == p[r])
            printf("%d\n", sum(i) != sum(r) ? -1 : abs(i - r));
          else
            printf("%d\n", sum(i) + sum(r) > 0
                               ? -1
                               : (i ? i - p[i] : 0) + (r ? r - p[r] : 0));
          break;
        default:
          assert(false);
          break;
      }
    }
  }
  return 0;
}
