#include <bits/stdc++.h>
using namespace std;
const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
const double EPS = 1e-8;
const double PI = acos(-1.0);
int popcount(int n) { return __builtin_popcount(n); }
int popcount(long long n) { return __builtin_popcountll(n); }
template <class T>
int SIZE(T a) {
  return a.size();
}
template <class T>
string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T>
T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] - '0');
  return res;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
void PrintSeq(T &a, int sz) {
  for (int i = 0; i < sz; i++) {
    cout << a[i];
    if (sz == i + 1)
      cout << endl;
    else
      cout << ' ';
  }
}
bool EQ(double a, double b) { return abs(a - b) < EPS; }
void fastStream() {
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
vector<string> split(string str, char del) {
  vector<string> res;
  for (int i = 0, s = 0; i < SIZE(str); i++) {
    if (str[i] == del) {
      if (i - s != 0) res.push_back(str.substr(s, i - s));
      s = i + 1;
    } else if (i == SIZE(str) - 1) {
      res.push_back(str.substr(s));
    }
  }
  return res;
}
class BIT {
 private:
  vector<long long> bit;
  int n;

 public:
  void init(int sz) {
    n = sz;
    for (int i = 0; i < n + 1; i++) bit.push_back(0);
  }
  long long sum(int i) {
    long long s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  void add(int i, long long x) {
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
};
int N;
vector<int> G[100001];
int depths[100001];
int root = 0;
int angOfNode[100001];
vector<int> elmsbyAng[100001];
map<int, int> posesOnAngSeq[100001];
BIT bitByAng[100001];
void dfs(int now, int depth, int prv, int angNumber) {
  depths[now] = depth;
  if (now != root) {
    angOfNode[now] = angNumber;
    elmsbyAng[angNumber].push_back(now);
    posesOnAngSeq[angNumber][now] = elmsbyAng[angNumber].size() - 1;
  }
  for (int i = 0; i < (int)G[now].size(); i++) {
    int to = G[now][i];
    if (to == prv) continue;
    int toAngNumber = angNumber;
    if (now == root) toAngNumber = i;
    dfs(to, depth + 1, now, toAngNumber);
  }
}
pair<int, int> es[400001];
int main() {
  fastStream();
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    G[v].push_back(u);
    G[u].push_back(v);
    es[i] = pair<int, int>(u, v);
  }
  for (int i = 1; i < N; i++)
    if ((int)G[i].size() > (int)G[root].size()) root = i;
  dfs(root, 0, -1, -1);
  for (int i = 0; i < (int)G[root].size(); i++)
    bitByAng[i].init((int)elmsbyAng[i].size());
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int type;
    cin >> type;
    if (type == 1 || type == 2) {
      int id;
      cin >> id;
      id--;
      pair<int, int> e = es[id];
      int tmp = -1;
      if (depths[e.first] > depths[e.second])
        tmp = e.first;
      else
        tmp = e.second;
      int ang = angOfNode[tmp];
      int pos = posesOnAngSeq[ang][tmp];
      pos++;
      if (type == 1)
        bitByAng[ang].add(pos, -1);
      else
        bitByAng[ang].add(pos, 1);
    } else if (type == 3) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      int res = 0;
      int sum = 0;
      if (a == root || b == root) {
        if (a == root) swap(a, b);
        int aa = depths[a];
        int ang = angOfNode[a];
        sum = bitByAng[ang].sum(aa);
        res = aa;
      } else if (angOfNode[a] == angOfNode[b]) {
        if (depths[a] > depths[b]) swap(a, b);
        int aa = depths[a];
        int bb = depths[b];
        int ang = angOfNode[a];
        sum = bitByAng[ang].sum(bb) - bitByAng[ang].sum(aa);
        res = depths[b] - depths[a];
      } else {
        int aa = depths[a];
        int ang1 = angOfNode[a];
        sum = bitByAng[ang1].sum(aa);
        int bb = depths[b];
        int ang2 = angOfNode[b];
        sum += bitByAng[ang2].sum(bb);
        res = aa + bb;
      }
      if (sum > 0)
        cout << -1 << endl;
      else
        cout << res << endl;
    }
  }
  return 0;
}
