#include <bits/stdc++.h>
using namespace std;
const int maxn = 101 * 1000;
vector<pair<int, int> > e;
int n;
int q;
int ma;
int de[maxn];
int d[maxn];
int dep[maxn];
vector<int> adj[maxn];
vector<int> id[maxn];
int ed[maxn];
int ej[maxn];
bool mark[maxn];
int now;
int md[maxn];
void dfs(int v) {
  md[now] = dep[v];
  mark[v] = true;
  for (int i = 0; i < (int)adj[v].size(); ++i)
    if (!mark[adj[v][i]]) {
      if (v == ma) now++;
      d[adj[v][i]] = now;
      ej[id[v][i]] = now;
      dep[adj[v][i]] = dep[v] + 1;
      ed[id[v][i]] = dep[v];
      dfs(adj[v][i]);
    }
}
struct node {
  node *l, *r;
  bool allb;
  node() {
    allb = true;
    l = r = NULL;
  }
  void insert(int x, int y, int p, int q) {
    if (!l) {
      l = new node;
      r = new node;
    }
    if (p == q - 1) {
      allb = y;
      return;
    }
    int mid = (p + q) / 2;
    if (x < mid)
      l->insert(x, y, p, mid);
    else
      r->insert(x, y, mid, q);
    allb = l->allb && r->allb;
  }
  bool isfree(int b, int e, int p, int q) {
    if (allb) return true;
    if (!l) {
      l = new node;
      r = new node;
    }
    if (b == p && e == q) return allb;
    int mid = (p + q) / 2;
    if (e <= mid) return l->isfree(b, e, p, mid);
    if (b >= mid) return r->isfree(b, e, mid, q);
    return l->isfree(b, mid, p, mid) && r->isfree(mid, e, mid, q);
  }
} root[maxn];
int ans(int x, int y) {
  if (x == y) return 0;
  if (dep[x] > dep[y]) swap(x, y);
  if (x == ma) {
    if (!root[d[y]].isfree(0, dep[y], 0, md[d[y]])) return -1;
    return dep[y];
  }
  if (d[x] != d[y]) {
    int ans1 = ans(ma, x);
    int ans2 = ans(ma, y);
    if (ans1 == -1 || ans2 == -1) return -1;
    return ans1 + ans2;
  }
  if (!root[d[y]].isfree(dep[x], dep[y], 0, md[d[y]])) return -1;
  return dep[y] - dep[x];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int t1, t2, t3;
  for (int i = 0; i < n - 1; ++i) {
    cin >> t1 >> t2;
    t1--;
    t2--;
    de[t1]++;
    de[t2]++;
    adj[t1].push_back(t2);
    adj[t2].push_back(t1);
    id[t1].push_back(i);
    id[t2].push_back(i);
  }
  for (int i = 0; i < n; ++i)
    if (de[i] > de[ma]) ma = i;
  dfs(ma);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> t1 >> t2;
    t2--;
    if (t1 == 1) root[ej[t2]].insert(ed[t2], 1, 0, md[ej[t2]]);
    if (t1 == 2) root[ej[t2]].insert(ed[t2], 0, 0, md[ej[t2]]);
    if (t1 == 3) {
      cin >> t3;
      t3--;
      cout << ans(t2, t3) << endl;
    }
  }
  return 0;
}
