#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101 * 1001, MOD = 1e9 + 7;
;
vector<int> a[MAXN];
vector<pair<int, int> > yal;
set<int> s[MAXN];
int mol[MAXN] = {}, q = 1, t[MAXN] = {};
set<int>::iterator it;
inline void dfs(int u, int p = -1) {
  if (p != -1) mol[u] = mol[p];
  for (auto v : a[u]) {
    if (v == p) continue;
    t[v] = t[u] + 1;
    dfs(v, u);
    if (p == -1) mol[u]++;
  }
}
inline int slove(int x, int y) {
  if (x == y) return 0;
  if (x == q) {
    int z = 1e9;
    if (s[mol[y]].size()) z = *s[mol[y]].begin();
    if (t[y] < z) return t[y];
    return -1;
  }
  if (mol[x] == mol[y]) {
    int z = -1;
    if (s[mol[x]].size()) z = *s[mol[x]].upper_bound(t[x]);
    if (z > t[y]) return t[y] - t[x];
    return -1;
  }
  int z = 1e9;
  if (s[mol[y]].size()) z = *s[mol[y]].begin();
  if (t[y] >= z) return -1;
  z = 1e9;
  if (s[mol[x]].size()) z = *s[mol[x]].begin();
  if (t[x] >= z) return -1;
  return t[x] + t[y];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int x, y;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
    if (a[x].size() > 2) q = x;
    if (a[y].size() > 2) q = y;
    yal.push_back({x, y});
    s[i].insert(1e9);
  }
  t[q] = 0;
  dfs(q);
  int m;
  cin >> m;
  while (m--) {
    cin >> x;
    if (x == 1) {
      cin >> x;
      y = yal[--x].first;
      x = yal[x].second;
      if (t[x] > t[y]) swap(y, x);
      s[mol[y]].erase(t[y]);
    } else if (x == 2) {
      cin >> x;
      y = yal[--x].first;
      x = yal[x].second;
      if (t[x] > t[y]) swap(y, x);
      s[mol[y]].insert(t[y]);
    } else if (x == 3) {
      cin >> x >> y;
      if (t[x] > t[y]) swap(x, y);
      cout << slove(x, y) << '\n';
    }
  }
}
