#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
const int inf = 1e9;
const int md = 1e9 + 7;
int n;
vector<int> g[maxn];
int root;
int len[maxn];
int u[maxn];
vector<vector<int> > fenf;
vector<int> num[maxn];
vector<pair<int, int> > z;
int sum(int w, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += fenf[w][r];
  return res;
}
void inc(int w, int i, int d) {
  for (; i < fenf[w].size(); i = (i | (i + 1))) fenf[w][i] += d;
}
int sum(int w, int l, int r) {
  --r;
  if (l == 0) return sum(w, r);
  return sum(w, r) - sum(w, l - 1);
}
void dfs(int v, int _len, int color) {
  len[v] = _len;
  u[v] = color;
  for (int i = 0; i < g[v].size(); ++i) {
    if (u[g[v][i]] == 0 && g[v][i] != root) {
      dfs(g[v][i], _len + 1, color);
      inc(color - 1, _len, 1);
      z[num[v][i]] = make_pair(color - 1, _len);
    }
  }
}
int dfs2(int v) {
  u[v] = 1;
  int res = 1;
  for (int i = 0; i < g[v].size(); ++i)
    if (u[g[v][i]] == 0) res += dfs2(g[v][i]);
  return res;
}
int main() {
  cin >> n;
  z.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    cin >> v >> u;
    --v, --u;
    g[v].push_back(u);
    g[u].push_back(v);
    num[v].push_back(i);
    num[u].push_back(i);
  }
  root = -1;
  for (int i = 0; i < n; ++i)
    if (root == -1 || g[root].size() < g[i].size()) root = i;
  vector<int> zero;
  u[root] = 1;
  for (int i = 0; i < g[root].size(); ++i) {
    int sz = dfs2(g[root][i]);
    ++sz;
    fenf.push_back(zero);
    fenf[i].resize(sz);
  }
  memset(u, 0, sizeof(u));
  for (int i = 0; i < g[root].size(); ++i) {
    inc(i, 0, 1);
    z[num[root][i]] = make_pair(i, 0);
    dfs(g[root][i], 1, i + 1);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int first;
      cin >> first;
      --first;
      inc(z[first].first, z[first].second, -1);
    }
    if (type == 2) {
      int first;
      cin >> first;
      --first;
      inc(z[first].first, z[first].second, 1);
    }
    if (type == 3) {
      int v, to;
      cin >> v >> to;
      --v, --to;
      if (u[v] != u[to]) {
        int tmp;
        if (v == root)
          tmp = sum(u[to] - 1, 0, len[to]);
        else if (to == root)
          tmp = sum(u[v] - 1, 0, len[v]);
        else
          tmp = sum(u[v] - 1, 0, len[v]) + sum(u[to] - 1, 0, len[to]);
        if (tmp == len[v] + len[to])
          cout << tmp;
        else
          cout << -1;
        cout << endl;
      } else {
        if (len[v] < len[to]) swap(v, to);
        int tmp = sum(u[v] - 1, len[to], len[v]);
        if (tmp == len[v] - len[to])
          cout << tmp;
        else
          cout << -1;
        cout << endl;
      }
    }
  }
  return 0;
}
