#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
map<int, vector<pair<int, int> > > e;
int n, m, root, cnt, deg[MAXN];
int c[MAXN], id[MAXN], to[MAXN], belong[MAXN];
inline int read() {
  int X = 0, flag = 0;
  char ch = 0;
  while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return flag ? -X : X;
}
template <typename F>
inline void write(F x, char ed = '\n') {
  static short st[30];
  short tp = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++tp] = x % 10, x /= 10;
  while (x);
  while (tp) putchar('0' | st[tp--]);
  putchar(ed);
}
inline void dfs(int x, int eid, int father) {
  id[x] = ++cnt;
  belong[id[x]] = id[father];
  to[eid] = id[x];
  for (int i = 0; i < (int)e[x].size(); ++i)
    if (e[x][i].second != eid) dfs(e[x][i].first, e[x][i].second, father);
}
inline void Insert(int x, int val) {
  for (; x <= n; x += x & (-x)) c[x] += val;
}
inline int Sum(int x) {
  int ret = 0;
  for (; x > 0; x -= x & (-x)) ret += c[x];
  return ret;
}
signed main() {
  n = read();
  for (int i = 1, x, y; i <= n - 1; ++i) {
    x = read(), y = read();
    e[x].push_back(make_pair(y, i));
    e[y].push_back(make_pair(x, i));
    deg[x]++, deg[y]++;
  }
  root = 1;
  for (int i = 1; i <= n; ++i)
    if (deg[i] > 2) root = i, i = n + 1;
  cnt = 0;
  id[root] = ++cnt;
  for (int i = 0; i < (int)e[root].size(); ++i)
    dfs(e[root][i].first, e[root][i].second, e[root][i].first);
  m = read();
  memset(c, 0, sizeof(c));
  for (int opt, x, y; m; m--) {
    opt = read();
    if (opt == 1) {
      x = read();
      Insert(to[x], -1);
    }
    if (opt == 2) {
      x = read();
      Insert(to[x], 1);
    }
    if (opt == 3) {
      x = read(), y = read();
      x = id[x], y = id[y];
      if (x == y) {
        puts("0");
        continue;
      }
      if (x > y) swap(x, y);
      if (x == 1) {
        int tem = Sum(y) - Sum(belong[y] - 1);
        if (tem)
          puts("-1");
        else
          printf("%d\n", y - belong[y] + 1);
      } else {
        if (belong[x] != belong[y]) {
          int tem = Sum(x) - Sum(belong[x] - 1) + Sum(y) - Sum(belong[y] - 1);
          if (tem)
            puts("-1");
          else
            printf("%d\n", x - belong[x] + 1 + y - belong[y] + 1);
        } else {
          int tem = Sum(y) - Sum(x);
          if (tem)
            puts("-1");
          else
            printf("%d\n", y - x);
        }
      }
    }
  }
  return 0;
}
