#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 222222;
struct SegTree {
  int res[maxn * 4];
  void build(int left, int right, int p) {
    res[p] = 1;
    int mid = (left + right) >> 1;
    if (left < right) {
      build(left, mid, p * 2);
      build(mid + 1, right, p * 2 + 1);
    }
  }
  void inverse(int left, int right, int x, int p) {
    if (left == right) {
      res[p] ^= 1;
      return;
    }
    int mid = (left + right) >> 1;
    if (x <= mid)
      inverse(left, mid, x, p * 2);
    else
      inverse(mid + 1, right, x, p * 2 + 1);
    push_up(p);
  }
  int get(int left, int right, int l, int r, int p) {
    if (l <= left && r >= right) {
      return res[p];
    }
    int mid = (left + right) >> 1;
    int ret = 1;
    if (l <= mid) ret &= get(left, mid, l, r, p * 2);
    if (ret && r > mid) ret &= get(mid + 1, right, l, r, p * 2 + 1);
    return ret;
  }
  void push_up(int p) { res[p] = res[p * 2] & res[p * 2 + 1]; }
};
int n;
struct HT {
  SegTree st;
  int depth[maxn], pos[maxn], stand[maxn], pre[maxn], father[maxn], sz[maxn],
      ch[maxn], dis[maxn];
  int last;
  vector<int> e[maxn];
  void init() {
    for (int i = 0; i < n; i++) {
      e[i].clear();
    }
  }
  void construct(int u, int fa, int dist) {
    father[u] = fa;
    sz[u] = 1;
    ch[u] = -1;
    dis[u] = dist;
    vector<int> &v = e[u];
    int maxch = 0;
    for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
      if (*it != fa) {
        construct(*it, u, dist + 1);
        sz[u] += sz[*it];
        if (sz[*it] >= maxch) {
          ch[u] = *it;
          maxch = sz[*it];
        }
      }
  }
  void go(int u, int fa, int root, int dep) {
    if (root == -1) root = u;
    depth[u] = dep;
    pre[u] = root;
    pos[u] = last;
    stand[last++] = u;
    if (ch[u] != -1) go(ch[u], u, root, dep);
    for (typeof(e[u].begin()) it = e[u].begin(); it != e[u].end(); it++)
      if (*it != fa && *it != ch[u]) go(*it, u, -1, dep + 1);
  }
  void build() {
    last = 0;
    construct(0, -1, 0);
    go(0, -1, -1, 0);
    st.build(0, n - 1, 1);
  }
  int lca(int u, int v) {
    if (depth[u] < depth[v]) swap(u, v);
    while (depth[u] > depth[v]) u = father[pre[u]];
    while (pre[u] != pre[v]) {
      u = father[pre[u]];
      v = father[pre[v]];
    }
    return stand[min(pos[u], pos[v])];
  }
  void inverse(int u, int v) {
    if (father[v] == u) swap(u, v);
    st.inverse(0, n - 1, pos[u], 1);
  }
  int distance(int u, int v) {
    int com = lca(u, v), dist = dis[u] + dis[v] - 2 * dis[com];
    int ans = 1;
    if (depth[u] < depth[v]) swap(u, v);
    while (depth[u] > depth[v]) {
      ans &= st.get(0, n - 1, pos[pre[u]], pos[u], 1);
      u = father[pre[u]];
    }
    while (pre[u] != pre[v]) {
      ans &= st.get(0, n - 1, pos[pre[u]], pos[u], 1);
      ans &= st.get(0, n - 1, pos[pre[v]], pos[v], 1);
      u = father[pre[u]];
      v = father[pre[v]];
    }
    int x = min(pos[u], pos[v]) + 1, y = max(pos[u], pos[v]);
    if (x <= y) ans &= st.get(0, n - 1, x, y, 1);
    if (ans == 1) return dist;
    return -1;
  }
} ht;
vector<pair<int, int> > edge;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  ht.init();
  edge.clear();
  int a, b, c;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    --a, --b;
    ht.e[a].push_back(b);
    ht.e[b].push_back(a);
    edge.push_back(make_pair(a, b));
  }
  ht.build();
  int m;
  cin >> m;
  while (m--) {
    cin >> a;
    if (a == 1 || a == 2) {
      cin >> b;
      ht.inverse(edge[b - 1].first, edge[b - 1].second);
    } else {
      cin >> b >> c;
      --b, --c;
      cout << ht.distance(b, c) << endl;
    }
  }
  return 0;
}
