#include <bits/stdc++.h>
using namespace std;
template <class 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 <class 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));
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
template <class T>
bool inside(T a, T b, T c) {
  return (b >= a && b <= c);
}
const long long INF64 = (long long)1E16;
int distsq2d(int x1, int y1, int x2, int y2) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
double dist2d(double x1, double y1, double x2, double y2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
double dist3d(double x1, double y1, double z1, double x2, double y2,
              double z2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2) + sqr(z1 - z2));
}
long long toInt64(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }
string itoa(long long a) {
  if (a == 0) return "0";
  string ret;
  for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);
  reverse(ret.begin(), ret.end());
  return ret;
}
vector<string> token(string a, string b) {
  const char *q = a.c_str();
  while (count(b.begin(), b.end(), *q)) q++;
  vector<string> oot;
  while (*q) {
    const char *e = q;
    while (*e && !count(b.begin(), b.end(), *e)) e++;
    oot.push_back(string(q, e));
    q = e;
    while (count(b.begin(), b.end(), *q)) q++;
  }
  return oot;
}
int isvowel(char s) {
  s = tolower(s);
  if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') return 1;
  return 0;
}
int isupper(char s) {
  if (s >= 'A' and s <= 'Z') return 1;
  return 0;
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
int check(int N, int pos) { return (N & (1 << pos)); }
int toggle(int N, int pos) {
  if (check(N, pos)) return N = reset(N, pos);
  return N = Set(N, pos);
}
void pbit(int N) {
  printf("(");
  for (int i = 10; i >= 0; i--) {
    bool x = check(N, i);
    cout << x;
  }
  puts(")");
}
int fx[] = {0, 0, 1, -1};
int fy[] = {1, -1, 0, 0};
vector<int> tree[100002];
int info[100002][3];
int read(int ti, int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree[ti][idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(int ti, int idx, int val) {
  while (idx <= (int)tree[ti].size() - 1) {
    tree[ti][idx] += val;
    idx += (idx & -idx);
  }
}
vector<int> g[100002];
int out[100002], deg[100002];
int oc = 0;
int chain = 0;
void dfs(int prev, int u) {
  int flag = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v != prev) {
      flag = 1;
      out[oc++] = v;
      dfs(u, v);
      oc--;
    }
  }
  if (!flag) {
    ++chain;
    tree[chain].resize(oc + 1);
    for (int i = 0; i < oc; i++) {
      info[out[i]][1] = chain;
      info[out[i]][2] = i + 1;
    }
  }
}
int dis(int a, int b, int root) {
  int ret;
  if (a == root) {
    int bt = info[b][1];
    int bn = info[b][2];
    ret = read(bt, bn - 1);
    if (bn - 1 != ret) return -1;
  }
  if (b == root) {
    int at = info[a][1];
    int an = info[a][2];
    ret = read(at, an - 1);
    if (an - 1 != ret) return -1;
  } else {
    int at = info[a][1];
    int an = info[a][2];
    int bt = info[b][1];
    int bn = info[b][2];
    if (at == bt) {
      if (an > bn) swap(an, bn);
      ret = read(at, bn - 1) - read(at, an - 1);
      if (bn - 1 - (an - 1) != ret) return -1;
    } else {
      ret = read(at, an - 1) + read(bt, bn - 1);
      if (an - 1 + bn - 1 != ret) return -1;
    }
  }
  return ret;
}
int upd(int a, int b, int val, int root) {
  int an = info[a][2];
  int bn = info[b][2];
  int at;
  if (an < bn) {
    swap(an, bn);
    swap(a, b);
  }
  at = info[a][1];
  update(at, an - 1, val);
  return val;
}
int edg[100002][3];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edg[i][1] = u;
    edg[i][2] = v;
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  int root = -1, alt = -1;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 2) alt = i;
    if (deg[i] > 2) root = i;
  }
  if (root == -1) {
    if (alt != -1)
      root = alt;
    else
      root = 1;
  }
  out[oc++] = root;
  dfs(-1, root);
  for (int i = 1; i <= n - 1; i++) {
    int u = edg[i][1];
    int v = edg[i][2];
    upd(u, v, 1, root);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type <= 2) {
      int no;
      scanf("%d", &no);
      int u = edg[no][1];
      int v = edg[no][2];
      if (type == 1)
        upd(u, v, 1, root);
      else
        upd(u, v, -1, root);
    } else {
      int a, b;
      scanf("%d%d", &a, &b);
      int ret = dis(a, b, root);
      printf("%d\n", ret);
    }
  }
}
