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 {
	public static InputReader in;
    public static PrintWriter pw;
 
 
 
	public static void main(String args[]) {
		new Thread(null, new Runnable() {
            public void run() {
                try{
                    solve();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();
    }
	//static HashSet<Integer> set;
	static ArrayList<Integer> g[];
	static ArrayList<Integer> h[];
	//static boolean visited[];
	static long edje=0;
    static boolean vis[];
	static int col[];
	static boolean[] visited;
	static int Parent[];
	static int Ans=0;
	static int min=Integer.MAX_VALUE;
	static boolean vis1[];
	static int degree[];
	static int f[];
	static  int size[];
	static int n;
	static int edjes=0;
	static int start=-1;
	static int end=-1;
	static boolean bool=false;
	static int Total=0;
	static int nums[];
	//static int a[];
	static int fr[];
	static int min1=Integer.MAX_VALUE;
	static TreeSet<String> set;
	static int a[];
	static int time1[];
	static int time2[];
	static int glob=0;
	static  HashSet<Integer>[] s;
	static int x,y;
	static StringBuilder p;
	static StringBuilder tmp=new StringBuilder();
	static HashMap<String,String> hm=new HashMap<String,String>();
	
	public static void solve(){
	
		 in = new InputReader(System.in);
		 pw = new PrintWriter(System.out);
	     int a=in.nextInt();
	     int b=in.nextInt();
	     int c=in.nextInt();
	     int m=in.nextInt();
	     Pair p[]=new Pair[m];
	     for(int i=0;i<m;i++)
	     {
	         p[i]=new Pair(in.nextInt(),in.readString());
	     }
	     Arrays.sort(p);
	     long sum=0;
	     int co=0;
	     for(int i=0;i<m;i++)
	     {
	         if(p[i].x.equals("USB"))
	         {
	             if(a>0)
	             {
	                 co++;	                
	                  sum+=(long)(p[i].c);
	                 a--;
	             }
	             else if(c>0)
	             {
	                 co++;
	                 sum+=(long)(p[i].c);
	                 c--;
	             }
	         }
	         else
	         {
	              if(b>0)
	             {
	                 co++;
	                sum+=(long)(p[i].c);
	                b--;
	             }
	             else if(c>0)
	             {
	                 co++;
	                 sum+=(long)(p[i].c);
	                 c--;
	             }
	         }
	      }
	      System.out.print(co+" "+sum);
	}
public static int check(int mid,int a[],int b[])
{
    int index=0;
    int i=0;
    int c=0;
    while(index<b.length&&i<a.length)
    {
        if((a[i]-x<=b[index])&&(b[index]<=a[i]+y))
        {
        
            p.append((i+1)+" "+(index+1)+"\n");
            c++;
            i++;
        }
        index++;
    }
   //System.out.println(c+" "+mid+"-----");
    return c;
}
	
	/*
	 SubTree Checker DFS (TO CHECK IF X IS IN A SUBTREE OF Y)
	public static void dfs(int curr)
	{
		visited[curr]=true;
		time1[curr]=glob++;
		for(int x:g[curr])
		{
		if(!visited[x])
			dfs(x);
		}
		time2[curr]=glob++;
	}
    
	
	
 
    /*NO OF EDJES IN WHOLE CONNECTED COMPONENTS
  
	public static void dfs1(int curr)
	{
		visited[curr]=true;
		for(int next:g[curr])
		{
			edje++;
			if(!visited[next])
				dfs1(next);
		}
	}
	/*SUM OF ALL SUBTREE NODE'S VLAUES DFS
	public static void dfs(int curr,int prev)
		{
		val[curr]=1;
			for(int x:g[curr])
			{
				if(x!=prev)
				{
		            dfs(x,curr);
		            val[curr]+=val[x];
					
			    }
			}
		}*/
	
		public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
				public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}
	static class Pair implements Comparable<Pair>{
	int c;
		String x;
		Pair(int mr,String i){
	     	c=mr;
			x=i;
			
		}
		@Override
		public int compareTo(Pair o) {
		     if(o.c<this.c)
		     return 1;
		     else
		     return -1;
			}
		
	}
	public static long gcd(long a, long b) {
		  if (b == 0) return a;
		  return gcd(b, a%b);
		}
	static class InputReader {
 
		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public   int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}