#include <bits/stdc++.h>
using namespace std;
const int INFint = 1147483547;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-13;
class SegmentTree {
 public:
  vector<int> t;
  int n;
  void build(vector<int> a) {
    n = a.size();
    for (int i = 0; i < n; i++) t[i + n] = a[i];
    for (int i = n - 1; i > 0; i--) t[i] = t[i << 1] + t[i << 1 | 1];
  }
  int get(int l, int r) {
    int res = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res += t[l++];
      if (r & 1) res += t[--r];
    }
    return res;
  }
  void modify(int p, int value) {
    for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
  }
  SegmentTree(int n) : n(n) { t.resize(2 * n, 0); }
  SegmentTree() {}
};
vector<vector<pair<int, int> > > g;
vector<int> color, dist;
vector<map<int, int> > ribs;
void dfs0(int v, int len, int p = -1) {
  dist[v] = len;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    dfs0(to, len + 1, v);
  }
}
void dfs2(int v, int len, int p) {
  dist[v] = len;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    if (0)
      cerr << v << "->" << to << ' ' << g[v][i].second << ' ' << len << endl;
    ribs[color[v]][g[v][i].second] = len;
    if (0) cerr << "kek";
    dfs2(to, len + 1, v);
  }
}
void dfs1(int v, int p, int cur) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    dfs1(to, v, cur + 1);
  }
}
void dfs(int v, int p, int cur) {
  color[v] = cur;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    dfs(to, v, cur);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  g.resize(n);
  int root = 0;
  vector<pair<int, int> > edges;
  dist.resize(n);
  color.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edges.push_back(make_pair(a, b));
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  for (int i = 0; i < n; i++)
    if (g[i].size() > 2) {
      root = i;
      break;
    }
  ribs.resize(g[root].size());
  dfs0(root, 0);
  color[root] = -1;
  int cur = 0;
  vector<SegmentTree> segs;
  for (int i = 0; i < g[root].size(); i++) {
    int to = g[root][i].first;
    dfs(to, root, cur++);
    dfs1(to, root, 0);
    dfs2(to, 1, root);
    segs.push_back(SegmentTree(ribs[i].size() + 1));
  }
  int m;
  cin >> m;
  for (int i = 0; i < n; i++)
    if (0) cerr << color[i] << ' ';
  if (0) cerr << endl;
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int id;
      cin >> id;
      id--;
      int a = edges[id].first, b = edges[id].second;
      int cl = color[a] != -1 ? color[a] : color[b];
      segs[cl].modify(ribs[cl][id], 0);
      continue;
    }
    if (type == 2) {
      int id;
      cin >> id;
      id--;
      int a = edges[id].first, b = edges[id].second;
      int cl = color[a] != -1 ? color[a] : color[b];
      if (0) cerr << "t2 " << cl << ' ' << id << ' ' << ribs[cl][id] << endl;
      segs[cl].modify(ribs[cl][id], 1);
      continue;
    }
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (0) cerr << "qr " << a << ' ' << b << endl;
    int ans = -1;
    if (color[a] == -1) {
      int cur = segs[color[b]].get(0, dist[b]);
      if (cur == 0) {
        ans = dist[b];
      }
      if (0) cerr << color[b] << ' ' << cur << endl;
      if (0) cerr << "a\n";
    }
    if (color[b] == -1) {
      int cur = segs[color[a]].get(0, dist[a]);
      if (cur == 0) {
        ans = dist[a];
      }
      if (0) cerr << "b\n";
    }
    if (color[a] == color[b]) {
      int r = dist[a], l = dist[b];
      if (l > r) swap(l, r);
      int cur = segs[color[a]].get(l, r);
      if (0) cerr << cur << endl;
      if (cur == 0) {
        ans = abs(dist[a] - dist[b]);
      }
    } else {
      int r = dist[a], r1 = dist[b];
      int cur = segs[color[a]].get(0, r);
      int cur1 = segs[color[b]].get(0, r1);
      if (cur == 0 && cur1 == 0) {
        ans = dist[a] + dist[b];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
