#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[111111];
vector<pair<long long, long long> > pov;
long long root, cnt;
long long w[111111], comp[111111], bit[111111];
long long capt[111111], pre[111111];
map<pair<long long, long long>, long long> m;
long long sum(long long ind) {
  long long res = 0;
  while (ind >= 0) {
    res += bit[ind];
    ind = (ind & (ind + 1)) - 1;
  }
  return res;
}
void add(long long ind, long long val) {
  while (ind < 111111) {
    bit[ind] += val;
    ind |= ind + 1;
  }
}
void DFS(long long x, long long par) {
  for (long long i = 0; i < adj[x].size(); i++) {
    long long tren = adj[x][i];
    if (par == tren) continue;
    m[{min(x, tren), max(x, tren)}] = cnt++;
    if (x == root) {
      comp[tren] = i + 1;
      capt[i + 1] = cnt - 1;
      pre[tren] = cnt - 1;
    } else {
      comp[tren] = comp[x];
      pre[tren] = cnt - 1;
    }
    w[tren] = w[x] + 1;
    DFS(tren, x);
  }
}
int main() {
  cnt = 1;
  root = -1;
  long long n;
  long long val = -1;
  scanf("%lld", &n);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
    pov.push_back({min(a, b), max(a, b)});
    if ((long long)adj[a].size() > val) {
      val = adj[a].size();
      root = a;
    }
    if ((long long)adj[b].size() > val) {
      val = adj[b].size();
      root = b;
    }
  }
  w[root] = 0;
  DFS(root, -1);
  long long q;
  scanf("%lld", &q);
  while (q--) {
    long long t, id1, id2;
    scanf("%lld %lld", &t, &id1);
    if (t == 3) scanf("%lld", &id2);
    if (t == 1) add(m[{pov[id1 - 1].first, pov[id1 - 1].second}], -1);
    if (t == 2) add(m[{pov[id1 - 1].first, pov[id1 - 1].second}], 1);
    if (t == 3) {
      long long pot, ans;
      if (comp[id1] == comp[id2]) {
        if (w[id1] > w[id2]) swap(id1, id2);
        ans = w[id2] - w[id1];
        pot = sum(pre[id2]) - sum(pre[id1]);
      } else {
        ans = w[id1] + w[id2];
        pot = sum(pre[id1]) - sum(capt[comp[id1]] - 1) + sum(pre[id2]) -
              sum(capt[comp[id2]] - 1);
      }
      if (pot == 0)
        printf("%lld\n", ans);
      else
        printf("-1\n");
    }
  }
  return 0;
}
