#include <bits/stdc++.h>
using namespace std;
int tam[100005], cadeia[100005];
int poscadeia[100005];
pair<int, int> edges[100005];
vector<pair<int, int> > adj[100005];
struct fenwick {
  int n;
  vector<int> ft;
  fenwick(int _n) {
    n = _n + 5;
    ft.assign(n, 0);
  }
  void update(int pos, int x) {
    pos++;
    for (int i = pos; i < n; i += i & (-i)) ft[i] += x;
  }
  int query(int pos) {
    pos++;
    int res = 0;
    for (int i = pos; i > 0; i -= i & (-i)) {
      res += ft[i];
    }
    return res;
  }
  int query(int esq, int dir) {
    int a = query(dir);
    int b = query(esq - 1);
    return a - b;
  }
};
void dfs(int u, int p, int idx, int pos) {
  tam[u] = 1;
  cadeia[u] = idx;
  poscadeia[u] = pos;
  for (auto par : adj[u])
    if (par.first != p) {
      dfs(par.first, u, idx, pos + 1);
      tam[u] += tam[par.first];
    }
}
int main() {
  cout.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].emplace_back(v, i);
    adj[v].emplace_back(u, i);
    edges[i + 1] = pair<int, int>(u, v);
  }
  int root = 1;
  for (int i = 1; i <= n; i++)
    if (adj[i].size() > adj[root].size()) root = i;
  vector<fenwick> vec;
  int numcadeia = 0;
  for (auto par : adj[root]) {
    dfs(par.first, root, numcadeia++, 0);
    fenwick ft(tam[par.first]);
    vec.emplace_back(ft);
  }
  int q;
  cin >> q;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1 || op == 2) {
      int id;
      cin >> id;
      int u, v;
      tie(u, v) = edges[id];
      if (v == root) swap(u, v);
      if (u == root) {
        int cad = cadeia[v];
        if (op == 1)
          vec[cad].update(0, -1);
        else
          vec[cad].update(0, +1);
      } else {
        if (poscadeia[u] < poscadeia[v]) swap(u, v);
        int cad = cadeia[u];
        if (op == 1)
          vec[cad].update(poscadeia[u], -1);
        else
          vec[cad].update(poscadeia[u], +1);
      }
    } else {
      int u, v;
      cin >> u >> v;
      if (u == v) {
        cout << 0 << endl;
        continue;
      }
      if (v == root) swap(u, v);
      if (u == root) {
        if (vec[cadeia[v]].query(poscadeia[v]) == 0)
          cout << poscadeia[v] + 1 << endl;
        else
          cout << -1 << endl;
      } else {
        if (cadeia[u] != cadeia[v]) {
          int sum_u = vec[cadeia[u]].query(poscadeia[u]);
          int sum_v = vec[cadeia[v]].query(poscadeia[v]);
          if (sum_u + sum_v == 0)
            cout << poscadeia[u] + poscadeia[v] + 2 << endl;
          else
            cout << -1 << endl;
        } else {
          int dir = max(poscadeia[u], poscadeia[v]);
          int esq = min(poscadeia[u], poscadeia[v]);
          if (vec[cadeia[u]].query(esq + 1, dir) == 0)
            cout << dir - esq << endl;
          else
            cout << -1 << endl;
        }
      }
    }
  }
  return 0;
}
