#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100001;
struct BIT {
  int n;
  vector<int> a, c;
  void init(int _n) {
    n = _n;
    a = vector<int>(n + 1, 0);
    c = vector<int>(n + 1, 0);
  }
  void update(int i, int val) {
    val -= a[i];
    a[i] += val;
    for (++i; i <= n; i += i & -i) {
      c[i] += val;
    }
  }
  int query(int i) {
    int ret = 0;
    while (i > 0) {
      ret += c[i];
      i &= i - 1;
    }
    return ret;
  }
  int query(int i, int j) { return query(j) - query(i); }
} bit[MAX_N];
int n, m, root;
int eu[MAX_N], ev[MAX_N], deg[MAX_N], depth[MAX_N], id[MAX_N];
int fa[18][MAX_N];
vector<int> e[MAX_N];
void dfs(int u, int f) {
  fa[0][u] = f;
  for (int i = 1; i < 18; ++i) {
    fa[i][u] = fa[i - 1][fa[i - 1][u]];
  }
  for (vector<int>::const_iterator i = e[u].begin(); i != e[u].end(); ++i) {
    if (*i != f) {
      depth[*i] = depth[u] + 1;
      id[*i] = id[u];
      dfs(*i, u);
    }
  }
  if (e[u].size() == 1) {
    bit[id[u]].init(depth[u]);
  }
}
int get_lca(int u, int v) {
  if (depth[u] < depth[v]) {
    swap(u, v);
  }
  for (int i = 0; i < 18; ++i) {
    if (((depth[u] - depth[v]) & 1 << i) != 0) {
      u = fa[i][u];
    }
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; --i) {
    int nu = fa[i][u];
    int nv = fa[i][v];
    if (nu != nv) {
      u = nu;
      v = nv;
    }
  }
  return fa[0][u];
}
void solve() {
  for (int i = root = 0; i < n; ++i) {
    if (deg[i] > deg[root]) {
      root = i;
    }
  }
  depth[root] = 0;
  for (int i = 0; i < 18; ++i) {
    fa[i][root] = root;
  }
  for (vector<int>::const_iterator i = e[root].begin(); i != e[root].end();
       ++i) {
    depth[*i] = 1;
    id[*i] = i - e[root].begin();
    dfs(*i, root);
  }
  for (int i = 1; i < n; ++i) {
    if (depth[eu[i]] > depth[ev[i]]) {
      swap(eu[i], ev[i]);
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int type, num, u, v;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &num);
      bit[id[ev[num]]].update(depth[eu[num]], 0);
    } else if (type == 2) {
      scanf("%d", &num);
      bit[id[ev[num]]].update(depth[eu[num]], 1);
    } else if (type == 3) {
      scanf("%d%d", &u, &v);
      --u, --v;
      int lca = get_lca(u, v);
      int t = 0;
      t += bit[id[u]].query(depth[lca], depth[u]);
      t += bit[id[v]].query(depth[lca], depth[v]);
      if (t == 0) {
        printf("%d\n", depth[u] + depth[v] - 2 * depth[lca]);
      } else
        puts("-1");
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &eu[i], &ev[i]);
    --eu[i], --ev[i];
    e[eu[i]].push_back(ev[i]);
    e[ev[i]].push_back(eu[i]);
    ++deg[eu[i]], ++deg[ev[i]];
  }
  solve();
  return 0;
}
