#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
#define N 100
#define INF 233333333
int capacity[N][N];
int flow[N][N];
int height[N];
int num;
bool dinic_bfs(int s, int t){
memset(height, 0, sizeof(height));
height[s] = 1;
queue<int> q;
q.push(s);
while (!q.empty()){
int temp = q.front();
q.pop();
for (int i = 0; i < num; i++)
if (!height[i] && capacity[temp][i] > flow[temp][i]){
height[i] = height[temp] + 1;
q.push(i);
}
}
return height[t] == 0? false: true;
}
int dinic_dfs(int s, int t, int minflow){
int result = 0;
for (int i = 0; i < num; i++)
if (minflow && height[s] + 1 == height[i] && capacity[s][i] > flow[s][i]){
int temp = i != t? dinic_dfs(i, t, min(minflow, capacity[s][i] - flow[s][i])): min(minflow, capacity[s][i] - flow[s][i]);
flow[s][i] += temp;
flow[i][s] -= temp;
minflow -= temp;
result += temp;
}
return result;
}
int dinic(int s, int t){
int answer = 0;
while (dinic_bfs(s, t))
answer += dinic_dfs(s, t, INF);
return answer;
}
int main(){
int t, n, m, x, y, c;
scanf("%d", &t);
for (int i = 0; i < t; i++){
scanf("%d %d", &n, &m);
num = n;
for (int j = 0; j < n; j++){
for (int l = 0; l < n; l++){
capacity[j][l] = 0;
flow[j][l] = 0;
}
height[j] = 0;
}
for (int j = 0; j < m; j++){
scanf("%d %d %d", &x, &y, &c);
capacity[x - 1][y - 1] += c;
}
printf("Case %d: %d\n", i + 1, dinic(0, n - 1));
}
return 0;
}