#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 105
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()
const double PI = acos(-1.0);
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
int nTest, n, a[maxN][maxN], pU[maxN];
vector<int> g[maxN];
bool visited[maxN];
bool DFS(int u) {
if (visited[u]) return false;
visited[u] = true;
for(int v: g[u]) {
if (pU[v] == -1 || DFS(pU[v])) {
pU[v] = u;
return true;
}
}
return false;
}
int main () {
scanf("%d", &nTest);
fto(iTest, 1, nTest) {
scanf("%d", &n);
fto(i, 1, n) fto(j, 1, n) scanf("%d", &a[i][j]);
int cnt = 0;
fto(x, -n, n) {
fto(u, 1, n) {
g[u].clear();
fto(v, 1, n)
if (a[u][v] == x) g[u].pb(v);
}
fto(v, 1, n) {
visited[v] = false;
pU[v] = -1;
}
fto(u, 1, n) {
if (DFS(u)) ++cnt;
}
}
int ans = n*n-cnt;
printf("Case #%d: %d\n", iTest, ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgY29tcGxleDxkb3V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AgICAgICAgICAgICAgICB2aXNpdGVkW3ZdID0gZmFsc2U7CiAgICAgICAgICAgICAgICBwVVt2XSA9IC0xOwogICAgICAgICAgICB9CgogICAgICAgICAgICBmdG8odSwgMSwgbikgewogICAgICAgICAgICAgICAgaWYgKERGUyh1KSkgKytjbnQ7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGludCBhbnMgPSBuKm4tY250OwogICAgICAgIHByaW50ZigiQ2FzZSAjJWQ6ICVkXG4iLCBpVGVzdCwgYW5zKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=