#include <bits/stdc++.h>
using namespace std;
const int tope = (1e5) + 10;
int id[tope];
int dist[tope];
int n, m, centro = 1;
int contador = 1;
vector<vector<int> > adj;
class FenwickTree {
 private:
  vector<int> ft;

 public:
  FenwickTree() {}
  FenwickTree(int n) { ft.assign(n + 1, 0); }
  int rsq(int b) {
    int sum = 0;
    for (; b; b -= (b & (-b))) {
      sum += ft[b];
    }
    return sum;
  }
  int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }
  void adjust(int k, int v) {
    for (; k < (int)ft.size(); k += (k & (-k))) ft[k] += v;
  }
};
int bfs(int u) {
  queue<int> q;
  q.push(u);
  dist[u] = 1;
  id[u] = contador;
  int top = 0, vec = 0;
  while (q.empty() == false) {
    top = q.front();
    q.pop();
    for (int i = 0; i < adj[top].size(); i++) {
      vec = adj[top][i];
      if (vec == centro) continue;
      if (dist[vec] == -1) {
        q.push(vec);
        dist[vec] = dist[top] + 1;
        id[vec] = contador;
      }
    }
  }
  return dist[top];
}
int main() {
  memset(id, -1, sizeof id);
  memset(dist, -1, sizeof dist);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<pair<int, int> > aristas;
  cin >> n;
  int x, y;
  adj.resize(n + 2);
  aristas.resize(n + 2);
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    aristas[i] = make_pair(x, y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cant = adj[centro].size();
  for (int i = 2; i <= n; i++) {
    if (adj[i].size() > cant) {
      centro = i;
      cant = adj[centro].size();
    }
    if (adj[centro].size() > 2) {
      break;
    }
  }
  cant = adj[centro].size();
  FenwickTree brazos[cant + 2];
  dist[centro] = 0;
  int tamanho;
  for (int i = 0; i < adj[centro].size(); i++) {
    int nodo = adj[centro][i];
    tamanho = bfs(nodo);
    FenwickTree F(tamanho + 2);
    brazos[contador] = F;
    contador++;
  }
  cin >> m;
  int a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (a == 3) {
      cin >> b >> c;
      if (b == c) {
        cout << "0"
             << "\n";
        continue;
      }
      int id1 = id[b];
      int id2 = id[c];
      if (id1 != id2) {
        if (brazos[id1].rsq(dist[b]) + brazos[id2].rsq(dist[c]) == 0) {
          cout << (dist[b] + dist[c]) << "\n";
        } else {
          cout << (-1) << "\n";
        }
      } else {
        if (dist[b] > dist[c]) {
          swap(b, c);
        }
        if (brazos[id1].rsq(dist[b] + 1, dist[c]) == 0) {
          cout << abs(dist[c] - dist[b]) << "\n";
        } else {
          cout << (-1) << "\n";
        }
      }
    } else {
      cin >> b;
      int nodo1 = aristas[b].first;
      int nodo2 = aristas[b].second;
      if (dist[nodo1] > dist[nodo2]) {
        swap(nodo1, nodo2);
      }
      int ID = id[nodo2];
      if (a == 1) {
        brazos[ID].adjust(dist[nodo2], -1);
      } else if (a == 2) {
        brazos[ID].adjust(dist[nodo2], +1);
      }
    }
  }
  return 0;
}
