#include <bits/stdc++.h>
using namespace std;
void require(bool cond, const string& message = "Runtime error") {
  if (!cond) {
    cerr << message << endl;
    assert(false);
  }
}
int next(int x) { return x | (x + 1); }
int prev(int x) { return x & (x + 1); }
void update(vector<int>& f, int i, int value) {
  while (i < f.size()) {
    f[i] += value;
    i = next(i);
  }
}
int sum(const vector<int>& f, int n) {
  int ret = 0;
  while (n >= 0) {
    ret += f[n];
    n = prev(n) - 1;
  }
  return ret;
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > edges(n - 1);
  vector<int> degs(n);
  vector<vector<pair<int, int> > > graph(n);
  for (int i = 0; i < int(n - 1); ++i) {
    cin >> edges[i].first >> edges[i].second;
    --edges[i].first, --edges[i].second;
    degs[edges[i].first]++;
    degs[edges[i].second]++;
    graph[edges[i].first].push_back(make_pair(edges[i].second, i));
    graph[edges[i].second].push_back(make_pair(edges[i].first, i));
  }
  int root = 0;
  for (int i = 0; i < int(n); ++i) {
    if (degs[i] > 2) root = i;
  }
  int m = degs[root];
  vector<vector<int> > fs(m, vector<int>());
  vector<vector<int> > vs(m, vector<int>());
  vector<int> brNum(n);
  map<int, int> vPos;
  vector<int> edgeToV(n - 1);
  queue<int> q;
  vector<bool> used(n);
  used[root] = true;
  for (int i = 0; i < int(graph[root].size()); ++i) {
    int v = graph[root][i].first;
    int ei = graph[root][i].second;
    brNum[v] = i;
    edgeToV[ei] = v;
    vPos[v] = 0;
    vs[i].push_back(v);
    q.push(v);
    used[v] = true;
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < int(graph[v].size()); ++i) {
      int u = graph[v][i].first;
      int ei = graph[v][i].second;
      if (used[u]) continue;
      used[u] = true;
      brNum[u] = brNum[v];
      vPos[u] = vPos[v] + 1;
      edgeToV[ei] = u;
      vs[brNum[u]].push_back(u);
      q.push(u);
    }
  }
  for (int i = 0; i < int(m); ++i) {
    fs[i] = vector<int>(vs[i].size());
  }
  int qn;
  cin >> qn;
  for (int it = 0; it < int(qn); ++it) {
    int type;
    cin >> type;
    if (type == 1) {
      int ei;
      cin >> ei;
      int v = edgeToV[ei - 1];
      update(fs[brNum[v]], vPos[v], -1);
    } else if (type == 2) {
      int ei;
      cin >> ei;
      int v = edgeToV[ei - 1];
      update(fs[brNum[v]], vPos[v], 1);
    } else {
      int a, b;
      cin >> a >> b;
      --a, --b;
      if (a == b) {
        cout << 0 << endl;
        continue;
      }
      if (b == root) swap(a, b);
      if (a == root) {
        if (sum(fs[brNum[b]], vPos[b]) == 0) {
          cout << vPos[b] + 1 << endl;
        } else {
          cout << -1 << endl;
        }
        continue;
      }
      if (brNum[a] == brNum[b]) {
        int pa = vPos[a], push_back = vPos[b];
        if (pa > push_back) swap(pa, push_back);
        int s = sum(fs[brNum[a]], push_back) - sum(fs[brNum[a]], pa);
        assert(s >= 0);
        if (s == 0) {
          cout << push_back - pa << endl;
        } else {
          cout << -1 << endl;
        }
      } else {
        if (sum(fs[brNum[a]], vPos[a]) + sum(fs[brNum[b]], vPos[b]) == 0) {
          cout << vPos[a] + 2 + vPos[b] << endl;
        } else {
          cout << -1 << endl;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
