#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:65536000")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct edge
{
int u, v;
edge() { u = v = 0; }
edge(int _u, int _v) { u = _u; v = _v; }
};
edge e[100100];
vector<int> all[100100];
vector<int> tree[100100];
int root, d[100100], tp[100100], pt, etp[100100], ed[100100], n, m;
void dfs(int x, int par)
{
tp[x] = pt;
if (all[x].size() == 1) tree[pt].resize(d[x]);
for (int i = 0; i < all[x].size(); i++)
{
if (all[x][i] == par) continue;
d[all[x][i]] = d[x] + 1;
dfs(all[x][i], x);
}
}
void add(int x, int y, int v)
{
for (int i = y; i < tree[x].size(); i = (i | (i + 1)))
tree[x][i] += v;
}
int get(int x, int y)
{
int ans = 0;
for (int i = y - 1; i >= 0; i = (i & (i + 1)) - 1)
ans += tree[x][i];
return ans;
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n - 1; i++)
{
int u, v;
scanf("%d%d", &u, &v); u--; v--;
e[i] = edge(u, v); all[u].push_back(v); all[v].push_back(u);
}
root = 0;
for (int i = 0; i < n; i++)
if (all[i].size() > all[root].size()) root = i;
for (int i = 0; i < all[root].size(); i++)
{
pt = i;
d[all[root][i]] = 1;
dfs(all[root][i], root);
}
for (int i = 0; i < n - 1; i++)
{
if (e[i].u == root) etp[i] = tp[e[i].v], ed[i] = 0;
else if (e[i].v == root) etp[i] = tp[e[i].u], ed[i] = 0;
else etp[i] = tp[e[i].u], ed[i] = min(d[e[i].u], d[e[i].v]);
}
scanf("%d", &m);
for (int i = 0; i < m; i++)
{
int t, u, v;
scanf("%d%d", &t, &u);
if (t == 3)
{
scanf("%d", &v); u--; v--;
int x = get(tp[u], d[u]), y = get(tp[v], d[v]);
if (tp[u] == tp[v])
{
if (x == y) printf("%d\n", abs(d[u] - d[v]));
else printf("-1\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