#include <bits/stdc++.h>
template <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
template <typename T>
inline T euclide(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <typename T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
using namespace std;
vector<int> adj[100007];
int L[100007], T[100007];
int subTree[100007];
int Start[100007];
int pos[100007], chainID[100007], ePos[100007];
int chainNo, ptr, n;
int BIT[100007], mxVal;
void Update(int idx, int val) {
  while (idx <= mxVal) BIT[idx] += val, idx += idx & -idx;
}
int Query(int idx) {
  int ans = 0;
  while (idx) ans += BIT[idx], idx -= idx & -idx;
  return ans;
}
void Dfs(int u, int p, int id, int l) {
  T[u] = p;
  L[u] = l;
  ePos[id] = u;
  subTree[u] = 1;
  for (int i = 0; i < adj[u].size(); i += 2) {
    int v = adj[u][i];
    int id = adj[u][i + 1];
    if (v == p) continue;
    Dfs(v, u, id, l + 1);
    subTree[u] += subTree[v];
  }
}
void HLD(int u, int p) {
  if (Start[chainNo] == -1) {
    Start[chainNo] = u;
  }
  chainID[u] = chainNo;
  pos[u] = ++ptr;
  int SpecialChild = -1, mx = -1;
  for (int i = 0; i < adj[u].size(); i += 2) {
    int v = adj[u][i];
    if (v != p && subTree[v] > mx) {
      mx = subTree[v];
      SpecialChild = i;
    }
  }
  if (SpecialChild != -1) HLD(adj[u][SpecialChild], u);
  for (int i = 0; i < adj[u].size(); i += 2) {
    if (i != SpecialChild) {
      int v = adj[u][i];
      if (v != p) {
        chainNo++;
        HLD(v, u);
      }
    }
  }
}
int ClimbeChain(int u, int v) {
  int ans = 0;
  while (1) {
    int uChain = chainID[u], vChain = chainID[v];
    if (uChain == vChain) {
      int tmp = 0;
      if (u != v) tmp = Query(pos[u]) - Query(pos[v]);
      ans += tmp;
      return ans;
    }
    int st = Start[uChain];
    int tmp = Query(pos[u]) - Query(pos[st] - 1);
    ans += tmp;
    u = T[st];
  }
}
int lca(int u, int v) {
  while (1) {
    int uChain = chainID[u], vChain = chainID[v];
    int uSt = Start[uChain], vSt = Start[vChain];
    if (uChain == vChain)
      return L[u] < L[v] ? u : v;
    else if (L[uSt] > L[vSt])
      u = T[uSt];
    else
      v = T[vSt];
  }
}
int Query(int p, int q) {
  int LCA = lca(p, q);
  int white = ClimbeChain(p, LCA) + ClimbeChain(q, LCA);
  if (white)
    return -1;
  else
    return L[p] + L[q] - 2 * L[LCA];
}
int main() {
  scanf("%d", &n);
  mxVal = n;
  Start[n] = -1;
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[u].push_back(i);
    adj[v].push_back(u);
    adj[v].push_back(i);
    Start[i] = -1;
  }
  chainNo = 1;
  ptr = 0;
  Dfs(1, -1, 0, 0);
  HLD(1, -1);
  int m;
  scanf("%d", &m);
  while (m--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int u;
      scanf("%d", &u);
      u = ePos[u];
      Update(pos[u], -1);
    } else if (type == 2) {
      int u;
      scanf("%d", &u);
      u = ePos[u];
      Update(pos[u], 1);
    } else {
      int u, v;
      scanf("%d%d", &u, &v);
      printf("%d\n", Query(u, v));
    }
  }
  return 0;
}
