public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		Edmons_karp f;
		int nNet = 1;
		while ((line = in.readLine()) != null) {
			int nNodes = Integer.parseInt(line.trim());
			if (nNodes == 0)
				break;
			out.append("Network " + nNet++ + "\n");
			f = new Edmons_karp(nNodes);
			int[] info = readInts(in.readLine());
			int s = info[0] - 1, t = info[1] - 1, c = info[2], a, b, w;
			for (int j = 0; j < c; j++) {
				info = readInts(in.readLine());
				a = info[0] - 1;
				b = info[1] - 1;
				w = info[2];
				if (f.g[a][b] == 0) {
					f.ady[a].add(b);
					f.ady[b].add(a);
				}
				f.g[a][b] += w;
				f.g[b][a] += w;
			}
			int mf = f.edmons_karp(s, t);
			out.append("The bandwidth is " + mf + ".\n\n");
		}
		System.out.print(out);
	}