import java.io.*;
import java.util.*;

public class soldiery_md implements Runnable {
	private Scanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new Scanner(new FileReader("soldiery.in"));
		out = new PrintWriter("soldiery.out");
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int[][] w = new int[n][3];
		int[][] r = new int[n][3];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				w[i][j] = in.nextInt();
			}
			for (int j = 0; j < 3; j++) {
				r[i][j] = in.nextInt();
			}
		}
		int[][][] a = new int[n + 1][m + 1][k + 1];
		int[][][] h = new int[n + 1][m + 1][k + 1];
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= m; j++)
				for (int l = 0; l <= k; l++)
					a[i][j][l] = -1;
		a[0][0][0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= m; j++) {
				for (int l = 0; l <= k; l++) {
					if (a[i + 1][j][l] < a[i][j][l]) {
						a[i + 1][j][l] = a[i][j][l];
						h[i + 1][j][l] = -1;
					}
					if (j == m)
						continue;
					for (int mask = 0; mask < 8; mask++) {
						int tests = 0;
						int dsum = 0;
						for (int t = 0; t < 3; t++) {
							if ((mask & (1 << t)) != 0) {
								tests++;
								dsum += r[i][t];
							} else {
								dsum += w[i][t];
							}
							if (l + tests > k)
								continue;
							if (a[i + 1][j + 1][l + tests] < a[i][j][l] + dsum) {
								a[i + 1][j + 1][l + tests] = a[i][j][l] + dsum;
								h[i + 1][j + 1][l + tests] = mask;
							}
						}
					}
				}
			}
		}
		for (int l = k - 1; l >= 0; l--) {
			if (a[n][m][l] > a[n][m][k])
				k = l;
		}
		out.println(a[n][m][k] + " " + k);
		String[] pars = new String[]{"STRENGTH", "HEIGHT", "WEIGHT"};
		String army = "";
		while (n > 0) {
			if (a[n][m][k] == 0)
				break;
			if (h[n][m][k] < 0) {
				n--;
				continue;
			}
			int tests = 0;
			for (int t = 0; t < 3; t++) {
				if ((h[n][m][k] & (1 << t)) != 0) {
					out.println(n + " " + pars[t]);
					tests++;
				}
			}
			army = n + " " + army;
			n--;
			m--;
			k -= tests;
		}
		out.println(army.trim());
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		new Thread(new soldiery_md()).start();
	}
}
