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

typedef long long LL;

LL S[20010];
vector<int> E[20010];
int n;
LL ans;

void dfs(int u, int fa)
{
	S[u] = 1;
	for (int i = 0; i < E[u].size(); i++) {
		int v = E[u][i];
		if (v == fa) continue;
		dfs(v, u);
		S[u] += S[v];
	}
	LL delta = (S[u] - 1) * (n - S[u]);
	LL sum = 0;
	for (int i = 0; i < E[u].size(); i++) {
		int v = E[u][i];
		if (v == fa) continue;
		sum += (S[u] - 1 - S[v]) * S[v];
	}
	sum >>= 1;
	sum += delta;
	if (sum > ans) {
		ans = sum;
	}
}


int main()
{
	ios::sync_with_stdio(false);
	int T;
	cin >> T;
	for (int cas = 1; cas <= T; cas++) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			E[i].clear();
			S[i] = 0;
		}
		for (int i = 1; i < n; i++) {
			int x, y;
			cin >> x >> y;
			E[x].push_back(y), E[y].push_back(x);
		}
		ans = 0;
		dfs(1, 0);
		printf("Case #%d: %lld\n", cas, ans);
		//for (int i = 1; i <= n; i++) cout << S[i] << ' '; cout << endl;
	}
	return 0;
}

