#include <bits/stdc++.h>
using namespace std;
struct tree {
  int* data = NULL;
  int len;
  void init(int l) {
    len = l;
    data = new int[(len + 1) * 4];
    for (int i = 0; i < (len + 1) * 4; i++) data[i] = 0;
  }
  void set(int tl, int tr, int pos, int x, int v) {
    if (tl == tr) {
      data[v] = x;
      return;
    }
    int m = (tl + tr) / 2;
    if (pos <= m)
      set(tl, m, pos, x, v * 2);
    else
      set(m + 1, tr, pos, x, v * 2 + 1);
    data[v] = data[2 * v] + data[2 * v + 1];
  }
  void set(int pos, int x) { set(0, len, pos, x, 1); }
  int get(int tl, int tr, int l, int r, int v) {
    if (tl > r || tr < l) return 0;
    if (tl >= l && tr <= r) return data[v];
    int m = (tl + tr) / 2;
    return get(tl, m, l, r, v * 2) + get(m + 1, tr, l, r, v * 2 + 1);
  }
  int get(int l, int r) { return get(0, len, l, r, 1); }
};
int n, m;
int root;
int st[100007];
int deep[100007];
int pd[100007];
int size[100007];
pair<int, int> eds[100007];
vector<int> gr[100007];
tree lst[100007];
void dfs(int cur, int last, int cpd) {
  if (last != -1) deep[cur] = deep[last] + 1;
  pd[cur] = cpd;
  size[cpd]++;
  for (int i = 0; i < gr[cur].size(); i++) {
    if (last != gr[cur][i]) {
      dfs(gr[cur][i], cur, cpd);
    }
  }
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin >> n;
  int u, v, x;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    eds[i] = make_pair(u, v);
    gr[u].push_back(v);
    gr[v].push_back(u);
    st[u]++;
    st[v]++;
  }
  root = 1;
  for (int i = 1; i <= n; i++)
    if (st[i] > 2) root = i;
  for (int i = 0; i < gr[root].size(); i++) {
    int to = gr[root][i];
    dfs(to, root, to);
  }
  for (int i = 0; i < gr[root].size(); i++) {
    int to = gr[root][i];
    lst[to].init(size[to]);
  }
  for (int i = 1; i <= n; i++)
    if (i != root) lst[pd[i]].set(deep[i], 1);
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (x == 1) {
      cin >> u;
      int a = eds[u].first;
      int b = eds[u].second;
      if (deep[a] < deep[b]) {
        swap(a, b);
      }
      lst[pd[a]].set(deep[a], 1);
    }
    if (x == 2) {
      cin >> u;
      int a = eds[u].first;
      int b = eds[u].second;
      if (deep[a] < deep[b]) {
        swap(a, b);
      }
      lst[pd[a]].set(deep[a], 0);
    }
    if (x == 3) {
      cin >> u >> v;
      if (pd[u] == pd[v]) {
        if (deep[u] > deep[v]) swap(u, v);
        int need = deep[v] - deep[u];
        if (lst[pd[u]].get(deep[u] + 1, deep[v]) == need) {
          cout << need << endl;
        } else {
          cout << -1 << endl;
        }
      } else {
        int need = deep[u] + deep[v];
        int has = 0;
        if (u != root) {
          has += lst[pd[u]].get(1, deep[u]);
        }
        if (v != root) {
          has += lst[pd[v]].get(1, deep[v]);
        }
        if (need == has) {
          cout << need << endl;
        } else {
          cout << -1 << endl;
        }
      }
    }
  }
  return 0;
}
