#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long sub[100004], lev[100004], a[100004], t[100004][17], n;
vector<long long> adj[100004];
void dfs(long long u, long long par) {
  long long i;
  sub[u] = 1;
  for (i = 0; i < adj[u].size(); i++) {
    long long p = adj[u][i];
    if (p == par) continue;
    lev[p] = lev[u] + 1;
    t[p][0] = u;
    dfs(p, u);
    sub[u] += sub[p];
  }
}
void build(long long n, long long x) {
  memset(t, -1, sizeof(t));
  dfs(x, -1);
  long long i, j;
  for (j = 1; (1 << j) <= n; j++) {
    for (i = 1; i <= n; i++) {
      if (t[i][j - 1] == -1) continue;
      t[i][j] = t[t[i][j - 1]][j - 1];
    }
  }
}
long long lca(long long p, long long q) {
  if (lev[p] < lev[q]) swap(p, q);
  long long i, j;
  for (i = 16; i >= 0; i--) {
    if (lev[p] - (1 << i) >= lev[q]) p = t[p][i];
  }
  if (p == q) return p;
  for (i = 16; i >= 0; i--) {
    if (t[p][i] != -1 && t[q][i] != -1 && t[p][i] != t[q][i]) {
      p = t[p][i];
      q = t[q][i];
    }
  }
  return t[p][0];
}
long long tree[100004 * 3];
void update(long long n, long long b, long long e, long long x, long long val) {
  if (b == e) {
    tree[n] = val;
    return;
  }
  long long mid = (b + e) >> 1, l = n * 2, r = l + 1;
  if (x <= mid)
    update(l, b, mid, x, val);
  else
    update(r, mid + 1, e, x, val);
  tree[n] = tree[l] + tree[r];
}
long long query(long long n, long long b, long long e, long long x,
                long long y) {
  if (b > y || e < x) return 0;
  if (b >= x && e <= y) return tree[n];
  long long mid = (b + e) >> 1, l = n * 2, r = l + 1;
  long long p = query(l, b, mid, x, y);
  long long p1 = query(r, mid + 1, e, x, y);
  return p + p1;
}
long long head[100004], chainno[100004], pos[100004], siz = 0, chain = 0;
void hld(long long u, long long par, long long f) {
  long long i;
  if (f == 1) {
    chain++;
    head[chain] = u;
  }
  chainno[u] = chain;
  pos[u] = ++siz;
  update(1, 1, n, pos[u], a[u]);
  long long mx = -1, ind = -1;
  for (i = 0; i < adj[u].size(); i++) {
    long long p = adj[u][i];
    if (p == par) continue;
    if (sub[p] > mx) {
      mx = sub[p];
      ind = p;
    }
  }
  if (ind != -1) hld(ind, u, 0);
  for (i = 0; i < adj[u].size(); i++) {
    long long p = adj[u][i];
    if (p == par || p == ind) continue;
    hld(p, u, 1);
  }
}
long long hld_query(long long u, long long v) {
  long long sum = 0;
  while (chainno[u] != chainno[v]) {
    if (lev[u] < lev[v]) swap(u, v);
    long long r = head[chainno[u]];
    sum += query(1, 1, n, pos[r], pos[u]);
    u = t[r][0];
  }
  if (lev[u] < lev[v]) swap(u, v);
  sum += query(1, 1, n, pos[v], pos[u]);
  return sum;
}
pair<long long, long long> ed[100004];
int main() {
  long long tc, u, v, i, j, m, x, y, cas = 0;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long max1 = 0;
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    ed[i] = {u, v};
    adj[u].push_back(v);
    adj[v].push_back(u);
    long long x = adj[u].size();
    max1 = max(max1, x);
    x = adj[v].size();
    max1 = max(max1, x);
  }
  long long root = 0;
  for (i = 1; i <= n; i++) {
    if (adj[i].size() == max1) {
      root = i;
      break;
    }
  }
  build(n, root);
  hld(root, -1, 1);
  long long q;
  cin >> q;
  while (q--) {
    cin >> m;
    if (m != 3) {
      cin >> x;
      long long u = ed[x].first;
      long long v = ed[x].second;
      if (t[u][0] == v) {
        a[u] ^= 1;
        update(1, 1, n, pos[u], a[u]);
      } else {
        a[v] ^= 1;
        update(1, 1, n, pos[v], a[v]);
      }
    } else {
      cin >> u >> v;
      long long p = lca(u, v);
      long long ans = hld_query(u, p) + hld_query(v, p) - 2 * a[p];
      if (ans)
        cout << "-1" << endl;
      else
        cout << lev[u] + lev[v] - 2 * lev[p] << endl;
    }
  }
  return 0;
}
