Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

Input

The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

The next line contains one integer m (0 ≤ m ≤ 3·105) — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109) — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

Output

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

Example

Input

2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2


Output

3 14

Note

In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	private final static Random rnd = new Random();

	class DSU {

		int parent[];
		int size;

		DSU(int size) {
			this.size = size;
			this.parent = new int[size];
			for (int i = 0; i < size; i++) {
				parent[i] = i;
			}
		}

		int get(int v) {
			int paren = parent[v];
			if (paren == v)
				return v;
			return parent[v] = get(paren);
		}

		void union(int a, int b) {
			a = get(a);
			b = get(b);
			if (a != b) {
				size--;
				parent[a] = b;
			}
		}

	}

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	int maxA(int[] a) {
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] > max) {
				max = a[i];

			}
		}
		return max;
	}

	int minA(int[] a) {
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {

		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

	// void initGraph(int a) {
	// for (int i = 0; i < a; i++) {
	// graph[i] = new ArrayList<Integer>();
	// }
	// }

	final static int[][] STEPS = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 }, { 0, 0 } };

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	final static char WALL = '*', NO_WALL = '.';

	void solve() throws IOException {
		int a = rI();
		int b = rI();
		int c = rI();
		int n = rI();
		ArrayList<Integer> usb = new ArrayList<Integer>();
		ArrayList<Integer> ps2 = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int cost = rI();
			String type = rS();
			if (type.equals("USB")) {
				usb.add(cost);
			} else {
				ps2.add(cost);
			}
		}
		Collections.sort(usb);
		Collections.sort(ps2);
		int flag1 = 0;
		int flag2 = 0;
		long ansCost = 0;
		long ansN = 0;
		while (a > 0 && usb.size() > flag1) {
			ansCost += (long) usb.get(flag1);
			a--;
			ansN++;
			flag1++;
		}
		while (b > 0 && ps2.size() > flag2) {
			ansCost += (long) ps2.get(flag2);
			b--;
			ansN++;
			flag2++;
		}
		while ((usb.size() > flag1 || flag2 < ps2.size()) && c > 0) {
			if (ps2.size() > flag2 && usb.size() > flag1) {
				int q1 = ps2.get(flag2);
				int q2 = usb.get(flag1);
				if (q1 > q2) {
					c--;
					flag1++;
					ansCost += (long) q2;
					ansN++;
				} else {
					ansCost += (long) q1;
					flag2++;
					c--;
					ansN++;
				}
			} else {
				if (ps2.size() > flag2) {
					ansCost += (long) ps2.get(flag2);
					c--;
					ansN++;
					flag2++;
				} else {
					ansCost += (long) usb.get(flag1);
					flag1++;
					ansN++;
					c--;
				}
			}

		}
		out.print(ansN + " " + ansCost);
	}
}