#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 7;
int n, root;
int depth[N], parent[N][18], subtreeSize[N], otherEnd[N];
int chainHead[N], chainID[N], posInBase[N], baseAra[N], chainNo, pos;
vector<int> g[N], edgeID[N], cost[N];
int T[N << 3];
void init() {
  chainNo = 0;
  pos = 0;
  for (int i = 0; i < n; i++) {
    g[i].clear();
    edgeID[i].clear();
    cost[i].clear();
    chainHead[i] = -1;
    for (int k = 0; k < 17; k++) parent[i][k] = -1;
  }
}
void DFS(int u, int p, int d) {
  depth[u] = d;
  parent[u][0] = p;
  subtreeSize[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) {
      otherEnd[edgeID[u][i]] = v;
      DFS(v, u, d + 1);
      subtreeSize[u] += subtreeSize[v];
    }
  }
}
void HLD(int u, int c, int p) {
  if (chainHead[chainNo] == -1) {
    chainHead[chainNo] = u;
  }
  chainID[u] = chainNo;
  posInBase[u] = pos;
  baseAra[pos++] = c;
  int special = -1;
  int ncost;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (p == v) continue;
    if (special == -1 || subtreeSize[special] < subtreeSize[v]) {
      special = v;
      ncost = cost[u][i];
    }
  }
  if (special != -1) {
    HLD(special, ncost, u);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (p == v) continue;
    if (v != special) {
      chainNo++;
      HLD(v, cost[u][i], u);
    }
  }
}
void build(int node, int b, int e) {
  if (b == e - 1) {
    T[node] = baseAra[b];
    return;
  }
  int mid = (b + e) >> 1, lc = node << 1, rc = lc | 1;
  build(lc, b, mid);
  build(rc, mid, e);
  T[node] = T[lc] + T[rc];
}
void sparseTable() {
  for (int j = 1; j < 17; j++) {
    for (int i = 0; i < n; i++) {
      if (parent[i][j - 1] != -1) {
        parent[i][j] = parent[parent[i][j - 1]][j - 1];
      }
    }
  }
}
void foo() {
  DFS(root, -1, 0);
  HLD(root, -1, -1);
  build(1, 0, pos);
  sparseTable();
}
void update(int node, int b, int e, int pid, int val) {
  if (b > pid || e <= pid) return;
  if (b == pid && b == e - 1) {
    T[node] = val;
    return;
  }
  int mid = (b + e) >> 1, lc = node << 1, rc = lc | 1;
  update(lc, b, mid, pid, val);
  update(rc, mid, e, pid, val);
  T[node] = T[lc] + T[rc];
}
int rangeQuery(int node, int b, int e, int l, int r) {
  if (b >= r || e <= l) return 0;
  if (l <= b && e <= r) return T[node];
  int mid = (b + e) >> 1, lc = node << 1, rc = lc | 1;
  return rangeQuery(lc, b, mid, l, r) + rangeQuery(rc, mid, e, l, r);
}
int chainQuery(int u, int v) {
  if (u == v) return 0;
  int chainOfu;
  int chainOfv = chainID[v];
  int chainRes = 0;
  while (true) {
    chainOfu = chainID[u];
    if (chainOfu == chainOfv) {
      if (u == v) break;
      int p = rangeQuery(1, 0, pos, posInBase[v] + 1, posInBase[u] + 1);
      chainRes += p;
      break;
    }
    int p =
        rangeQuery(1, 0, pos, posInBase[chainHead[chainOfu]], posInBase[u] + 1);
    chainRes += p;
    u = chainHead[chainOfu];
    u = parent[u][0];
  }
  return chainRes;
}
int LCA(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = 16; i >= 0; i--) {
    int pi = parent[u][i];
    if (pi != -1 && depth[pi] >= depth[v]) u = pi;
  }
  if (u == v) return v;
  for (int i = 16; i >= 0; i--) {
    if (parent[u][i] != parent[v][i]) {
      u = parent[u][i];
      v = parent[v][i];
    }
  }
  return parent[u][0];
}
void pathQuery(int u, int v) {
  int lca = LCA(u, v);
  int res = chainQuery(u, lca) + chainQuery(v, lca);
  if (res != depth[u] + depth[v] - 2 * depth[lca]) res = -1;
  printf("%d\n", res);
}
void change(int i, int val) {
  int u = otherEnd[i];
  update(1, 0, pos, posInBase[u], val);
}
int main() {
  scanf("%d", &n);
  root = 0;
  init();
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
    cost[u].push_back(1);
    cost[v].push_back(1);
    edgeID[u].push_back(i);
    edgeID[v].push_back(i);
  }
  foo();
  int m;
  scanf("%d", &m);
  while (m--) {
    int operation;
    scanf("%d", &operation);
    if (operation == 3) {
      int a, b;
      scanf("%d %d", &a, &b);
      pathQuery(a - 1, b - 1);
    } else {
      int a;
      scanf("%d", &a);
      change(a - 1, operation == 1 ? 1 : 0);
    }
  }
  return 0;
}
