#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = 3.14159265358979323846264338327950288419716939937511;
const double eps = 1e-9;
char ch_ch_ch[1 << 20];
string gs() {
  scanf("%s", ch_ch_ch);
  return string(ch_ch_ch);
}
string gl() {
  gets(ch_ch_ch);
  return string(ch_ch_ch);
}
vector<vector<int> > G;
vector<pair<int, int> > E;
int n;
int root;
int gi[111111];
int d[111111];
vector<vector<int> > fen;
int br;
void dfs(int v, int pr, int ind, int dist) {
  gi[v] = ind;
  d[v] = dist;
  fen[ind].push_back(0);
  for (int i = 0; i < (G[v].size()); ++i)
    if (E[G[v][i]].second != pr) dfs(E[G[v][i]].second, v, ind, dist + 1);
}
void fenmod(int ind, int p, int val) {
  for (; p < fen[ind].size(); p += p & (-p)) {
    fen[ind][p - 1] += val;
  }
}
int fensum(int ind, int p) {
  int sum = 0;
  for (; p > 0; p -= p & (-p)) sum += fen[ind][p - 1];
  return sum;
}
int calc(int u, int v) {
  if (d[u] > d[v]) swap(u, v);
  int ind = gi[v];
  if (u == v) return 0;
  if (fensum(ind, d[v]) - fensum(ind, d[u]) > 0) return -1000000000;
  return d[v] - d[u];
}
void solution() {
  scanf("%d", &n);
  G.resize(n);
  for (int i = 0; i < (n - 1); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    G[u].push_back(E.size());
    E.push_back(make_pair(u, v));
    G[v].push_back(E.size());
    E.push_back(make_pair(v, u));
  }
  root = 0;
  for (int i = (1); i < (G.size()); ++i)
    if (G[i].size() > 2) {
      root = i;
      break;
    }
  fen.resize(G[root].size());
  br = G[root].size();
  for (int i = 0; i < (br); ++i) {
    fen[i].push_back(0);
    dfs(E[G[root][i]].second, root, i, 1);
  }
  int m;
  scanf("%d", &m);
  d[root] = 0;
  for (int it = 0; it < (m); ++it) {
    int tp;
    scanf("%d", &tp);
    if (tp == 1 || tp == 2) {
      int e;
      scanf("%d", &e);
      --e;
      e *= 2;
      int v = (d[E[e].second] < d[E[e].first]) ? E[e].first : E[e].second;
      fenmod(gi[v], d[v], (tp == 1) ? -1 : 1);
    } else {
      int u, v;
      scanf("%d%d", &u, &v);
      --u, --v;
      if (d[u] > d[v]) swap(u, v);
      int res;
      if (gi[u] == gi[v])
        res = calc(u, v);
      else
        res = calc(root, u) + calc(root, v);
      if (res < 0)
        printf("-1\n");
      else
        printf("%d\n", res);
    }
  }
}
int main(int argc, char** argv) {
  solution();
  return 0;
}
