#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using i3 = pair<int, ii>;
using li = pair<ll, int>;
using lii = pair<ll, ii>;
using vi = vector<int>;
using vl = vector<ll>;
using vli = vector<li>;
using vii = vector<ii>;
using vi3 = vector<i3>;
using vlii = vector<lii>;
const int N = 2e5 + 5;
const ll INF = 1e7;
const double eps = 1e-12, PI = acos(-1);
int n, m;
int p[N];
int heavy[N];
int segTreePos[N];
int chainHead[N];
vii adj[N];
ll st[N << 2];
int to[N];
int dep[N];
void dfs(int u, int pr) {
  for (ii A : adj[u]) {
    int v = A.second;
    int e = A.first;
    if (v == pr) continue;
    p[v] = u;
    dep[v] = 1 + dep[u];
    to[e] = v;
    heavy[u] = v;
    dfs(v, u);
  }
}
void update(int p, int l, int r, int dx, int val) {
  if (l == r) {
    st[p] = 1ll * val;
    return;
  }
  int mid = (l + r) >> 1;
  if (dx <= mid)
    update(p << 1, l, mid, dx, val);
  else
    update(p << 1 | 1, mid + 1, r, dx, val);
  st[p] = st[p << 1] + st[p << 1 | 1];
}
ll rsq(int p, int l, int r, int S, int E) {
  if (l >= S && r <= E) return st[p];
  if (l > E || r < S) return 0;
  int mid = (l + r) >> 1;
  return rsq(p << 1, l, mid, S, E) + rsq(p << 1 | 1, mid + 1, r, S, E);
}
void build_chains(int start) {
  dfs(start, 0);
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] == 0 || heavy[p[i]] != i) {
      for (int j = i; j != 0; j = heavy[j]) {
        segTreePos[j] = ++pos;
        chainHead[j] = i;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    update(1, 1, n + 2, segTreePos[to[i]], 1);
  }
}
ll query(int u, int v) {
  ll ans = 0;
  for (; chainHead[u] != chainHead[v]; u = p[chainHead[u]]) {
    if (dep[chainHead[u]] < dep[chainHead[v]]) swap(u, v);
    ans += rsq(1, 1, n + 2, segTreePos[chainHead[u]], segTreePos[u]);
  }
  if (dep[u] < dep[v]) swap(u, v);
  if (u != v) {
    ans += rsq(1, 1, n + 2, segTreePos[v] + 1, segTreePos[u]);
  }
  return ans;
}
void solve(int cs) {
  scanf("%d", &n);
  int U = 1;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back({i, v});
    adj[v].push_back({i, u});
    if (adj[u].size() > 2) U = u;
    if (adj[v].size() > 2) U = v;
  }
  build_chains(U);
  int q;
  scanf("%d", &q);
  while (q--) {
    int type;
    scanf("%d", &type);
    int a, b, e;
    if (type == 3) {
      scanf("%d %d", &a, &b);
      ll ans = query(a, b);
      printf("%lld\n", ans >= INF ? -1 : ans);
    } else {
      scanf("%d", &e);
      update(1, 1, n + 2, segTreePos[to[e]], type == 1 ? 1 : INF);
    }
  }
}
int main() {
  int t = 1;
  for (int cs = 1; t--; cs++) {
    solve(cs);
  }
  return 0;
}
