#include #include #include #include

using namespace std;

const int buf_len = 4567; char buf[buf_len], *bufb(buf), *bufe(bufb + 1); #define readBuf() {
if (++ bufb == bufe)
bufe = (bufb = buf) + fread(buf, 1, sizeof(buf), stdin);
} #define readInt(x) {
register int s(0);
do {
readBuf();
} while (!isdigit(*bufb));
do {
s = s * 10 + *bufb - 48;
readBuf();
} while (isdigit(*bufb));
x = s;
}

typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int)

struct edge { int t, v; edge *next; };

const int maxn = 1000009; const int maxl = 25; const int inf = 0x3f3f3f3f;

namespace rtree { int n, d[maxn], ut[maxn][maxl]; int dfo[maxn], dfb[maxn]; edge ebuf_arr[maxn « 1], *ebuf(ebuf_arr), *head[maxn];

inline void addEdge(int u, int v) {
	ebuf-> t = v;
	ebuf-> next = head[u];
	head[u] = ebuf ++;
}
void init() {
	readInt(n);
	memset(head, 0, sizeof(head));
	for (int i = 1; i < n; ++ i) {
		int u, v;
		readInt(u);
		readInt(v);
		addEdge(u, v);
		addEdge(v, u);
	}
	static int stc[maxn];
	int tst(1), dfn(0);
	memset(d, 0, sizeof(d));
	d[stc[1] = 1] = 1;
	while (tst) {
		int p(stc[tst --]);
		dfo[dfb[p] = ++ dfn] = p;
		for (int i = 1; i < maxl; ++ i)
			ut[p][i] = ut[ut[p][i - 1]][i - 1];
		for (edge* e = head[p]; e; e = e-> next)
			if (!d[e-> t]) {
				d[e-> t] = d[p] + 1;
				ut[e-> t][0] = p;
				stc[++ tst] = e-> t;
			}
	}
}
int LCA(int u, int v) {
	if (d[u] < d[v])
		swap(u, v);
	for (int i = maxl - 1; i >= 0; -- i)
		if (d[ut[u][i]] >= d[v])
			u = ut[u][i];
	if (u == v)
		return u;
	for (int i = maxl - 1; i >= 0; -- i)
		if (ut[u][i] != ut[v][i]) {
			u = ut[u][i];
			v = ut[v][i];
		}
	return ut[u][0];
}
inline bool cmpDfn(const int& a, const int& b) {
	return dfb[a] < dfb[b];
}
inline int dis(int u, int v) {
	return d[u] - d[v];
}

};

namespace ftree { int n, q[maxn], stc[maxn], tst; int tiq(0), ciq[maxn] = {0}; int sz[maxn], f[maxn][3], g[maxn][3], dfo[maxn]; int sf, sg; dint tot; edge ebuf_arr[maxn « 1], *ebuf, *head[maxn];

inline void addEdge(int u, int v, int w) {
	ebuf-> t = v;
	ebuf-> v = w;
	ebuf-> next = head[u];
	head[u] = ebuf ++;
}
void DP() {
	int dfn(0);
	tot = 0;
	stc[tst = 1] = 1;
	sf = inf, sg = -inf;
	tot = 0;
	while (tst) {
		int p(stc[tst --]);
		dfo[++ dfn] = p;
		for (edge* e = head[p]; e; e = e-> next)
			stc[++ tst] = e-> t;
	}
	for (int i = dfn; i; -- i) {
		int p(dfo[i]);
		sz[p] = (ciq[p] == tiq);
		f[p][0] = f[p][1] = -1;
		g[p][0] = g[p][1] = -1;
		if (ciq[p] == tiq)
			f[p][0] = g[p][0] = 0;
		for (edge* e = head[p]; e; e = e-> next) {
			tot += _l e-> v * sz[e-> t] * (n - sz[e-> t]);
			sz[p] += sz[e-> t];
			int vn(f[e-> t][0] + e-> v);
			if (f[p][0] == -1 || vn < f[p][0]) {
				f[p][1] = f[p][0];
				f[p][0] = vn;
			}
			else if (f[p][1] == -1 || vn < f[p][1])
				f[p][1] = vn;
			if (f[p][1] > -1)
				sf = min(sf, f[p][0] + f[p][1]);
			vn = g[e-> t][0] + e-> v;
			if (g[p][0] == -1 || vn > g[p][0]) {
				g[p][1] = g[p][0];
				g[p][0] = vn;
			}
			else if (g[p][1] == -1 || vn > g[p][1])
				g[p][1] = vn;
			if (g[p][1] > -1)
				sg = max(sg, g[p][0] + g[p][1]);
		}
	}
	f[1][2] = g[1][2] = -1;
	for (int i = 1; i <= dfn; ++ i) {
		int p(dfo[i]);
		if (f[p][2] > -1)
			sf = min(sf, f[p][0] + f[p][2]);
		if (g[p][2] > -1)
			sg = max(sg, g[p][0] + g[p][2]);
		for (edge* e = head[p]; e; e = e-> next) {
			int vn;
			if (f[e-> t][0] + e-> v == f[p][0])
				vn = f[p][1];
			else
				vn = f[p][0];
			if (vn == -1 || f[p][2] < vn)
				vn = f[p][2];
			if (vn > -1)
				vn += e-> v;
			f[e-> t][2] = vn;
			if (g[e-> t][0] + e-> v == g[p][0])
				vn = g[p][1];
			else
				vn = g[p][0];
			if (vn == -1 || g[p][2] > vn)
				vn = g[p][2];
			if (vn > -1)
				vn += e-> v;
			g[e-> t][2] = vn;
		}
	}
	printf(lld " %d %d\n", tot, sf, sg);
}

void sov() {
	readInt(n);
	++ tiq;
	for (int i = 0; i < n; ++ i) {
		readInt(q[i]);
		ciq[q[i]] = tiq;
	}
	sort(q, q + n, rtree :: cmpDfn);
	tst = 1;
	head[stc[tst] = 1] = 0;
	ebuf = ebuf_arr;
	for (int i = 0; i < n; ++ i) {
		int p(q[i]), a(rtree :: LCA(p, stc[tst]));
		if (a == stc[tst]) {
			if (p != stc[tst]) {
				head[p] = 0;
				stc[++ tst] = p;
			}
		}
		else {
			while (rtree :: d[stc[tst - 1]] >= rtree :: d[a]) {
				addEdge(stc[tst - 1], stc[tst], rtree :: dis(stc[tst], stc[tst - 1]));
				-- tst;
			}
			if (a != stc[tst]) {
				head[a] = 0;
				addEdge(a, stc[tst], rtree :: dis(stc[tst], a));
				stc[tst] = a;
			}
			head[p] = 0;
			stc[++ tst] = p;
		}
	}
	while (tst > 1) {
		addEdge(stc[tst - 1], stc[tst], rtree :: dis(stc[tst], stc[tst - 1]));
		-- tst;
	}
	DP();
}

};

int main() { #ifndef ONLINE_JUDGE freopen(".in", “r”, stdin); #endif

rtree :: init();
int q;
readInt(q);
while (q --)
	ftree :: sov();

}