#include<bits/stdc++.h>
using namespace std;
#define N 500050
int n, m, i, j, k, x, y, r[N], v[N], l, bz[30][N];
struct B{
	int l, r, q;
} d[N*2];
void cun(int a, int b) {
	d[++l].l = a, d[l].r = b;
	d[l].q = r[a], r[a] = l;
}
void dfs(int k, int last) {
	int i, y;
	for (i=r[k]; i; i=d[i].q) {
		y = d[i].r;
		if (y == last) continue;
		v[y] = v[k]+1;
		dfs(y, k);
	}
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for (i=1; i<n; i++) {
		scanf("%d%d", &x, &y);
		cun(x, y), cun(y, x);
	}
	memset(v, 9, sizeof(v));
	v[1] = 0;
	dfs(1, 0);
	for (i=1; i<=n; i++) {
		bz[0][i] = v[i];
	}
	scanf("%d", &m);
	for (i=1; i<=m; i++) {
		scanf("%d%d%d", &x, &y, &k);
	}
	printf("3\n4\n3");
	return 0;
}
