#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;
int c, tt, n;
int dep[N];
vector<int> g[N];

void dfs(int u, int f) {
	dep[u] = dep[f] + 1;
	for (int v : g[u]) {
		if (v == f) continue;
		dfs(v, u);
	}
}

void solve() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v), g[v].push_back(u);
	}
	dfs(1, 0);
	int q;
	cin >> q;
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		cout << dep[r] << endl;
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
} 
