#include <bits/stdc++.h>
using namespace std;
class Solver {
 private:
  long long res, n, k;
  map<int, vector<int> > g;

 public:
  Solver();
  void Work();
  ~Solver();
};
class Beard {
 private:
  map<int, int> id_chain;
  map<int, int> id_subid;
  map<int, map<int, int> > whites;
  void walk(int, int, int, int, map<int, map<int, int> >&);

 public:
  Beard(map<int, map<int, int> >&);
  bool isOnSameChain(int, int);
  bool isConnect(int, int);
  int dist(int, int);
  int dist(int);
  int centre;
  void toggleColor(int, int);
  void operator[](int id) {
    cout << "id:\t" << id << endl;
    cout << "chain:\t" << id_chain[id] << endl;
    cout << "subid:\t" << id_subid[id] << endl;
  }
};
int main() {
  Solver one;
  one.Work();
  return 0;
}
Solver::Solver() : res(0) {}
Solver::~Solver() {}
void Solver::Work() {
  vector<pair<int, int> > adjs;
  map<int, map<int, int> > edgs;
  int n, m;
  cin >> n;
  while (--n) {
    int a, b;
    cin >> a >> b;
    edgs[a][b] = edgs[b][a] = 1;
    adjs.push_back(pair<int, int>(a, b));
  }
  Beard bd(edgs);
  cin >> m;
  while (m--) {
    int ty, a, b;
    cin >> ty;
    if (ty == 3) {
      cin >> a >> b;
      if (bd.isOnSameChain(a, b)) {
        if (bd.isConnect(a, b))
          cout << bd.dist(a, b) << endl;
        else
          cout << -1 << endl;
      } else {
        if (bd.isConnect(a, bd.centre) && bd.isConnect(b, bd.centre))
          cout << bd.dist(a) + bd.dist(b) << endl;
        else
          cout << -1 << endl;
      }
    } else {
      cin >> a;
      bd.toggleColor(adjs[a - 1].first, adjs[a - 1].second);
    }
  }
}
void Beard::toggleColor(int ida, int idb) {
  if (ida == centre) swap(ida, idb);
  int chain = id_chain[ida];
  int x = id_subid[ida], y = id_subid[idb];
  if (x > y) swap(x, y);
  if (whites[chain][x])
    whites[chain].erase(x);
  else
    whites[chain][x] = 1;
}
int Beard::dist(int ida) {
  int x = id_subid[ida];
  return x;
}
int Beard::dist(int ida, int idb) {
  int x = id_subid[ida], y = id_subid[idb];
  return abs(x - y);
}
bool Beard::isConnect(int ida, int idb) {
  if (ida == centre) swap(ida, idb);
  int chain = id_chain[ida];
  int x = id_subid[ida], y = id_subid[idb];
  if (x > y) swap(x, y);
  map<int, int>::iterator found = whites[chain].lower_bound(x);
  if (found == whites[chain].end() || found->first >= y) return true;
  return false;
}
bool Beard::isOnSameChain(int ida, int idb) {
  if (ida == centre || idb == centre) return true;
  return id_chain[ida] == id_chain[idb];
}
Beard::Beard(map<int, map<int, int> >& edgs)
    : centre(1), id_chain(), id_subid(), whites() {
  for (typeof(edgs.begin()) from = edgs.begin(); from != edgs.end(); ++from)
    if (from->second.size() > 2) centre = from->first;
  id_subid[centre] = 0;
  int chain = 1;
  for (typeof(edgs[centre].begin()) to = edgs[centre].begin();
       to != edgs[centre].end(); ++to)
    walk(to->first, centre, 1, chain++, edgs);
}
void Beard::walk(int root, int p, int dep, int chain,
                 map<int, map<int, int> >& edgs) {
  id_chain[root] = chain;
  id_subid[root] = dep;
  for (typeof(edgs[root].begin()) to = edgs[root].begin();
       to != edgs[root].end(); ++to) {
    if (to->first == p) continue;
    walk(to->first, root, dep + 1, chain, edgs);
  }
}
