/*--------------------------------------------------------------*/
/* ACM ICPC 2007-2008                                           */
/* Northeastern European Regional Contest                       */
/* St Petersburg - Barnaul - Tashkent - Batumi, November 28, 200*/
/*--------------------------------------------------------------*/
/* Problem F. Fund Management                                   */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Michael Dvorkin                        */
/*--------------------------------------------------------------*/
 
import java.io.*;
import java.util.*;

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

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	int[][] d = new int[10][20];
	int[][] e = new int[10][20];
	int[][] up = new int[13000][8];
	int[][] down = new int[13000][8];
	int[] sum = new int[13000];
	int all = 0;
	int maxLots;
	int[] maxHold = new int[8];
	
	void calc() {
		d[0][0] = 1;
		for (int i = 0; i <= 8; i++) {
			for (int j = 0; j <= 8; j++) {
				for (int k = 0; k <= 8; k++) {
					d[i + 1][j + k] += d[i][j];
				}
			}
		}
		for (int i = 0; i <= 8; i++) {
			for (int j = 0; j <= 8; j++) {
				e[i][j] = (j > 0 ? e[i][j - 1] : 0) + d[i][j];
			}
		}
		all = e[8][8];
	}
	
	int encode(int[] a, int day) {
		int res = 0, sum = 8;
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i]; j++) {
				res += e[7 - i][sum];
				sum--;
			}
		}
		return day * all + res;
	}
	
	int sum(int[] a) {
		int res = 0;
		for (int x : a)
			res += x;
		return res;
	}
	
	int decode(int code, int[] a) {
		int day = code / all;
		code %= all;
		int sum = 8;
		for (int i = 0; i < a.length; i++) {
			a[i] = 0;
			while (code >= e[7 - i][sum]) {
				code -= e[7 - i][sum];
				a[i]++;
				sum--;
			}
		}
		return day;
	}
	
	void calc2() {
		int[] a = new int[8];
		for (int c = 0; c < all; c++) {
			decode(c, a);
			sum[c] = sum(a);
			for (int i = 0; i < 8; i++) {
				if (sum[c] < maxLots && a[i] < maxHold[i]) {
					a[i]++;
					int c2 = encode(a, 0);
					up[c][i] = c2 - c;
					a[i]--;
				} else {
					up[c][i] = all;
				}
			}
			for (int i = 0; i < 8; i++) {
				if (a[i] > 0) {
					a[i]--;
					int c2 = encode(a, 0);
					down[c][i] = c2 - c;
					a[i]++;
				} else {
					down[c][i] = all;
				}
			}
		}
	}
	
	long[] cash;
	int[] previous;
	byte[] operation;
	String[] name;
	
	private void print(int code) {
		int prev = previous[code];
		int oper = operation[code];
		if (prev < 0)
			return;
		print(prev);
		if (oper == 0) {
			out.println("HOLD");
			return;
		}
		if (oper > 0)
			out.print("BUY ");
		else {
			out.print("SELL ");
			oper *= -1;
		}
		oper--;
		out.println(name[oper]);
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		calc();
		in = new Scanner(new FileReader("fund.in"));
		out = new PrintWriter("fund.out");
		long initCash = Math.round(100 * in.nextDouble());
		int days = in.nextInt();
		int n = in.nextInt();
		maxLots = in.nextInt();
		name = new String[n];
		cash = new long[(days + 1) * all];
		Arrays.fill(cash, -1);
		previous = new int[(days + 1) * all];
		operation = new byte[(days + 1) * all];
		int[] lot = new int[n];
		long[][] p = new long[n][days];
		for (int i = 0; i < n; i++) {
			name[i] = in.next();
			lot[i] = in.nextInt();
			maxHold[i] = in.nextInt();
			for (int j = 0; j < days; j++) {
				p[i][j] = Math.round(100 * in.nextDouble()) * lot[i];
			}
		}
		calc2();
		int init = encode(new int[n], 0);
		cash[init] = initCash;
		previous[init] = -1;
		operation[init] = -1;
		for (int code = 0; code < cash.length; code++) {
			long money = cash[code];
			if (money < 0)
				continue;
			int cc = code % all;
			int day = code / all;
			int held = sum[cc];
			if (day == days) {
				if (held > 0)
					continue;
				out.printf("%.2f\n", money * 0.01);
				print(code);
				break;
			}
			int code2 = code + all;
			if (money > cash[code2]) {
				cash[code2] = money;
				previous[code2] = code;
				operation[code2] = 0;
			}
			for (int i = 0; i < n; i++) {
				long sum = p[i][day];
				int add = up[cc][i];
				if (add != all) {
					long money2 = money - sum;
					if (money2 >= 0) {
						int code3 = code2 + add;
						if (money2 > cash[code3]) {
							cash[code3] = money2;
							previous[code3] = code;
							operation[code3] = (byte) (1 + i);
						}
					}
				}
				add = down[cc][i];
				if (add != all) {
					long money2 = money + sum;
					int code3 = code2 + add;
					if (money2 > cash[code3]) {
						cash[code3] = money2;
						previous[code3] = code;
						operation[code3] = (byte) - (1 + i);
					}
				}
			}
		}
		in.close();
		out.close();
	}
	
	public static void main(String[] args) {
		new Thread(new fund_md()).start();
	}

}
