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

public class soldiery_rs implements Runnable {
	public static void main(String[] args) {
		new Thread(new soldiery_rs()).start();
	}

	private int inf = 1000000000;
	private int[] maskLength = { 0, 1, 1, 2, 1, 2, 2, 3 };
	private String[] type = { "STRENGTH", "HEIGHT", "WEIGHT" };

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private int[] us;
	private int[] uh;
	private int[] uw;
	private int[] ts;
	private int[] th;
	private int[] tw;
	private int[][] soldCost;
	
	private int getCost(int u, int mask) {
		int result = 0;
		if ((mask & 1) != 0) {
			result += ts[u];  
		} else {
			result += us[u];
		}
		if ((mask & 2) != 0) {
			result += th[u];  
		} else {
			result += uh[u];
		}
		if ((mask & 4) != 0) {
			result += tw[u];  
		} else {
			result += uw[u];
		}
		return result;
	}
	
	private int[] ansPeople;
	private int testNum;
	private int curPeople;
	private int[] testWho;
	private int[] testType;
	private int[][][] ans;
	
	private void printAnswer(int n, int m, int k) {
		if (n == 0) {
			return;
		}
		
		if (ans[n][m][k] == ans[n - 1][m][k]) {
			printAnswer(n - 1, m, k);
			return;
		}
		
		ansPeople[curPeople++] = n;
		for (int mask = 0; mask < 8; mask++) {
			if (k >= maskLength[mask]) {
				int cur = soldCost[n - 1][mask] + ans[n - 1][m - 1][k - maskLength[mask]];
				if (cur == ans[n][m][k]) {
					if ((mask & 1) != 0) {
						testWho[testNum] = n;
						testType[testNum] = 1;
						testNum++;
					}
						
					if ((mask & 2) != 0) {
						testWho[testNum] = n;
						testType[testNum] = 2;
						testNum++;
					}
					
					if ((mask & 4) != 0) {
						testWho[testNum] = n;
						testType[testNum] = 3;
						testNum++;
					}
					
					printAnswer(n - 1, m - 1, k - maskLength[mask]);
					return;
				}
			}
		}
	}
	
	private void solve() throws IOException {
		Scanner in = new Scanner(new File("soldiery.in"));
		PrintWriter out = new PrintWriter("soldiery.out");
		
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		us = new int[n];
		uh = new int[n];
		uw = new int[n];
		ts = new int[n];
		th = new int[n];
		tw = new int[n];
		for (int i = 0; i < n; i++) {
			us[i] = in.nextInt();
			uh[i] = in.nextInt();
			uw[i] = in.nextInt();
			ts[i] = in.nextInt();
			th[i] = in.nextInt();
			tw[i] = in.nextInt();
		}
		
		soldCost = new int[n][8];
		for (int i = 0; i < n; i++) {
			for (int mask = 0; mask < 8; mask++) {
				soldCost[i][mask] = getCost(i, mask);
			}
		}
		
		ans = new int[n + 1][m + 1][k + 1];
		for (int i = 0; i <= m; i++) {
			for (int j = 0; j <= k; j++) {
				ans[0][i][j] = -inf;
			}
		}
		ans[0][0][0] = 0;
		
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				for (int t = 0; t <= k; t++) {
					ans[i][j][t] = ans[i - 1][j][t];
					if (j == 0) {
						continue;
					}
					for (int mask = 0; mask < 8; mask++) {
						if (t >= maskLength[mask]) {
//							int cur = getCost(i - 1, mask) + ans[i - 1][j - 1][t - maskLength[mask]];
							int cur = soldCost[i - 1][mask] + ans[i - 1][j - 1][t - maskLength[mask]];
							ans[i][j][t] = Math.max(ans[i][j][t], cur);
						}
					}
				}
			}
		}
		
		int answer = 0;
		int ansi = 0;
		for (int i = 0; i <= k; i++) {
			if (ans[n][m][i] > answer) {
				answer = ans[n][m][i];
				ansi = i;
			}
		}
		
		curPeople = 0;
		testNum = 0;
		ansPeople = new int[m];
		testWho = new int[k];
		testType = new int[k];
		printAnswer(n, m, ansi);
		
		out.println(answer + " " + testNum);
		for (int i = 0; i < testNum; i++) {
			out.println(testWho[i] + " " + type[testType[i] - 1]);
		}
		
		for (int i = m - 1; i >= 0; i--) {
			out.print(ansPeople[i] + " ");
		}
		out.println();
		
		in.close();
		out.close();
	}
}
