#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> vec[N];
vector<pair<int, int> > adj;
int Par[N], siz[N], dep[N], now = 1;
int head[N], chain[N], st[N], tim;
int T[3 * N + 2], cost[N], n;
void dfs(int u, int p) {
  Par[u] = p;
  siz[u] = 1;
  for (auto v : vec[u]) {
    if (v == p) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    siz[u] += siz[v];
  }
}
void hld(int u, int p) {
  if (head[now] == -1) head[now] = u;
  chain[u] = now;
  st[u] = ++tim;
  int id = -1;
  for (auto v : vec[u]) {
    if (v == p) continue;
    if (id == -1 || siz[id] < siz[v]) id = v;
  }
  if (id != -1) hld(id, u);
  for (auto v : vec[u]) {
    if (v == p || v == id) continue;
    ++now;
    hld(v, u);
  }
}
int _lca(int u, int v) {
  while (head[chain[u]] != head[chain[v]]) {
    if (dep[head[chain[u]]] < dep[head[chain[v]]])
      v = Par[head[chain[v]]];
    else
      u = Par[head[chain[u]]];
  }
  return (dep[u] > dep[v]) ? v : u;
}
void updt(int nod, int lo, int hi, int id) {
  if (lo == hi) {
    T[nod] ^= 1;
    return;
  }
  int mid = (lo + hi) >> 1;
  if (id <= mid)
    updt(2 * nod, lo, mid, id);
  else
    updt(2 * nod + 1, mid + 1, hi, id);
  T[nod] = (T[2 * nod] + T[2 * nod + 1]);
}
int qry(int nod, int lo, int hi, int l, int r) {
  if (hi < l || lo > r) return 0;
  if (lo >= l && hi <= r) return T[nod];
  int mid = (lo + hi) >> 1;
  return (qry(2 * nod, lo, mid, l, r) + qry(2 * nod + 1, mid + 1, hi, l, r));
}
int process(int u, int v) {
  int ret = 0;
  while (true) {
    if (chain[u] == chain[v]) return (ret + qry(1, 1, n, st[v] + 1, st[u]));
    ret = (ret + qry(1, 1, n, st[head[chain[u]]], st[u]));
    u = Par[head[chain[u]]];
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int m = n - 1;
  memset(head, -1, sizeof head);
  while (m--) {
    int u, v, w;
    cin >> u >> v;
    vec[u].push_back(v);
    vec[v].push_back(u);
    adj.push_back(make_pair(u, v));
  }
  dep[1] = 1;
  dfs(1, -1);
  hld(1, -1);
  int q;
  cin >> q;
  while (q--) {
    int typ;
    cin >> typ;
    if (typ <= 2) {
      int id;
      cin >> id;
      int u = adj[id - 1].first, v = adj[id - 1].second;
      int now = (dep[u] > dep[v]) ? u : v;
      updt(1, 1, n, st[now]);
    } else {
      int u, v;
      cin >> u >> v;
      int lca = _lca(u, v);
      int res = process(u, lca) + process(v, lca);
      if (res == 0)
        res = dep[u] + dep[v] - 2 * dep[lca];
      else
        res = -1;
      cout << res << "\n";
    }
  }
}
