#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 10;
struct EDGE {
  int u, v;
  int index;
  int rid;
} edge[M];
vector<EDGE> adj[M];
int rootnode = -1;
int visited[M];
int dis[M];
int noderid[M];
int newid = 1;
void dfs(int node) {
  visited[node] = 1;
  for (vector<EDGE>::iterator it = adj[node].begin(); it != adj[node].end();
       it++) {
    int u = (*it).u;
    int v = (*it).v;
    int nxt = (u == node ? v : u);
    if (visited[nxt] == 0) {
      dis[nxt] = dis[node] + 1;
      noderid[nxt] = newid;
      edge[(*it).index].rid = newid;
      newid++;
      dfs(nxt);
    }
  }
  return;
}
int par[M];
int Find(int x) { return x == par[x] ? x : par[x] = Find(par[x]); }
int S[M];
int keyid;
struct TREE {
  int l, r;
  int num0;
} tree[4 * M];
void build(int l, int r, int node) {
  tree[node].l = l;
  tree[node].r = r;
  tree[node].num0 = 0;
  if (l == r) {
    return;
  } else {
    int mid = (l + r) / 2;
    build(l, mid, 2 * node);
    build(mid + 1, r, 2 * node + 1);
    return;
  }
}
void modify(int node, int index, int dnum) {
  int l = tree[node].l;
  int r = tree[node].r;
  tree[node].num0 += dnum;
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  if (index <= mid) {
    modify(2 * node, index, dnum);
  } else {
    modify(2 * node + 1, index, dnum);
  }
  return;
}
int query(int ql, int qr, int node) {
  int l = tree[node].l;
  int r = tree[node].r;
  if (ql <= l && r <= qr) {
    return tree[node].num0;
  }
  int mid = (l + r) / 2;
  int s1, s2;
  s1 = s2 = 0;
  if (ql <= mid) {
    s1 = query(ql, qr, 2 * node);
  }
  if (qr > mid) {
    s2 = query(ql, qr, 2 * node + 1);
  }
  return s1 + s2;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    edge[i].u = u;
    edge[i].v = v;
    edge[i].index = i;
    adj[u].push_back(edge[i]);
    adj[v].push_back(edge[i]);
  }
  int maxd = 0;
  for (int i = 1; i <= n; i++) {
    int isize = adj[i].size();
    if (isize > maxd) {
      maxd = isize;
      rootnode = i;
    }
  }
  dfs(rootnode);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 1; i <= n - 1; i++) {
    int u = edge[i].u;
    int v = edge[i].v;
    if (u != rootnode && v != rootnode) {
      int pu = Find(u);
      int pv = Find(v);
      if (pu != pv) {
        par[pu] = pv;
      }
    }
  }
  for (vector<EDGE>::iterator it = adj[rootnode].begin();
       it != adj[rootnode].end(); it++) {
    int u = (*it).u;
    int v = (*it).v;
    int nxt = (u == rootnode ? v : u);
    S[keyid++] = noderid[nxt];
  }
  sort(S, S + keyid);
  build(1, n - 1, 1);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int itype;
    cin >> itype;
    if (itype == 1) {
      int iedge;
      cin >> iedge;
      int id = edge[iedge].rid;
      modify(1, id, -1);
    }
    if (itype == 2) {
      int iedge;
      cin >> iedge;
      int id = edge[iedge].rid;
      modify(1, id, 1);
    }
    if (itype == 3) {
      int u, v;
      cin >> u >> v;
      int ui = noderid[u];
      int vi = noderid[v];
      if (vi > ui) {
        int tmp = ui;
        ui = vi;
        vi = tmp;
        tmp = u;
        u = v;
        v = tmp;
      }
      if (u == v) {
        cout << "0" << endl;
      } else {
        if (vi == 0) {
          int id = lower_bound(S, S + keyid, ui) - S;
          if (id == keyid || S[id] > ui) {
            id--;
          }
          int sum0 = query(S[id], ui, 1);
          int ans = (sum0 > 0 ? -1 : dis[u]);
          cout << ans << endl;
        } else {
          int pu = Find(u);
          int pv = Find(v);
          if (pu == pv) {
            int sum0 = query(vi + 1, ui, 1);
            int ans = (sum0 > 0 ? -1 : dis[u] - dis[v]);
            cout << ans << endl;
          } else {
            int id1 = lower_bound(S, S + keyid, vi) - S;
            if (id1 == keyid || S[id1] > vi) {
              id1--;
            }
            int sum1 = query(S[id1], vi, 1);
            int id2 = lower_bound(S, S + keyid, ui) - S;
            if (id2 == keyid || S[id2] > ui) {
              id2--;
            }
            int sum2 = query(S[id2], ui, 1);
            int ans = (sum1 + sum2 > 0 ? -1 : dis[u] + dis[v]);
            cout << ans << endl;
          }
        }
      }
    }
  }
  return 0;
}
