#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
#define max(a,b) (a>b? a:b)
const int maxn = 205;
const int inf = 0x3f3f3f3f;
int m, n;
bool vis[maxn];
int pre[maxn];
int c[maxn][maxn];
bool bfs(int s, int t) {
queue<int> que;
memset(pre, -1, sizeof(pre));
memset(vis, false, sizeof(vis));
pre[s] = s;
vis[s] = true;
que.push(s);
int p;
while (que.size()) {
p = que.front();
que.pop();
for (int i = 1; i <= m; i++) {
if (c[p][i] > 0 && !vis[i]) {
pre[i] = p;
vis[i] = true;
if (t == i) return true;
que.push(i);
}
}
}return false;
}
int EK(int s, int t) {
int max = 0;
int f;
while (bfs(s, t)) {
f = inf;
for (int i = t; i != s; i = pre[i]) {
f = min(f, c[pre[i]][i]);
}
for (int i = t; i != s; i = pre[i]) {
c[i][pre[i]] += f;
c[pre[i]][i] -= f;
}
max += f;
}return max;
}
int main() {
int t;
cin >> t;
int e = 0;
while (t--)
{
cin >> m >> n;
int s, t, q;
memset(c, 0, sizeof(c));
for (int i = 0; i < n; i++) {
cin >> s >> t >> q;
c[s][t] += q;
}cout << "Case " << ++e << ": ";
cout << EK(1, m) << endl;
}
//ystem("pause");
return 0;
}
源点 到汇点之间的最大流问题