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.util.*; 
            import java.math.*;
            import java.io.*;
            import java.text.DecimalFormat;
            import java.math.BigInteger;
            public class Main{
                //static int d=20;
                static long mod=1000000007 ;
                static HashMap<String,Double> hm=new HashMap<>(); 
                static ArrayList<ArrayList<Integer>> arr;
                static long[] dp1,dp2;
                static int[] a;
                static int[] vis,num;
                static long max;
                static int id;
                public static void main(String[] args)  throws IOException {
                    boolean online =false;
                    String fileName = "C-large-practice";
                    PrintWriter out; 
                    if (online) {
                        s.init(new FileInputStream(new File(fileName + ".in")));
                         out= new PrintWriter(new FileWriter(fileName + "out.txt"));
                    }
                     else {
                        s.init(System.in);   
                    
                        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
                    }//r,b,y,g
                    
                    int a,b,c;
                    a=s.ni();
                    b=s.ni();
                    c=s.ni();
                    int m=s.ni();
                    ArrayList<Long> arr1=new ArrayList<>();
                    ArrayList<Long> arr2=new ArrayList<>();
                    for(int i=0;i<m;i++){
                        long x=s.nl();
                        if(s.ns().charAt(0)=='P')
                            arr2.add(x);
                        else
                            arr1.add(x);
                    }
                    Collections.sort(arr1);
                    Collections.sort(arr2);
                    int n1=Math.min(a,arr1.size());
                    int n2=Math.min(b,arr2.size());
                    long ans=0;
                    int id1,id2;
                    id1=id2=0;
                    for( ;id1<n1;id1++){
                        ans+=arr1.get(id1);
                    }
                    for( ;id2<n2;id2++){
                        ans+=arr2.get(id2);
                    }
                    ArrayList<Long> arr3=new ArrayList<>();
                    while(id2<arr2.size())
                        arr3.add(arr2.get(id2++));
                    while(id1<arr1.size())
                        arr3.add(arr1.get(id1++));
                    Collections.sort(arr3);
                    int n3=Math.min(c,arr3.size());
                    //out.println(arr3);
                    for(int i=0;i<n3;i++)
                        ans+=arr3.get(i);
                    out.println((n1+n2+n3)+" "+ans);

                    out.close();
     
                }
                
                public static long gcd(long a, long b){
                        if (a == 0) return b;
                        return gcd(b % a, a);
                }
                    
                public static boolean check(long x){
                    if(x%4==0 || x%7==0 || x%11==0)
                        return true;
                    if(x<4 || x<7 || x<11)
                        return false;
                    if(x%2==0){
                        return check(x/2);
                    }
                    else
                        return check(x/2) && check((x+1)/2);
                }
                public static int angle(int x1,int x2,int x3,int y1,int y2,int y3){
                    long val=(y2-y1)*1L*(x3-x2)-(y3-y2)*1L*(x2-x1);
                    if(val<0)
                        return 1;
                    else if(val>0)
                        return -1;
                    else
                        return 0;
                }
                
                static class BIT{
                
                    int N;
                    int tree[];
                    
                    BIT(int N){
                        this.N = N;
                        tree = new int[N + 1];
                    }
                    
                    void update(int idx){
                        while(idx <= N){
                            tree[idx]++;
                            idx += (idx & -idx);
                        }
                    }
                    
                    int query(int l,int r){
                        if(l == 1)
                            return read(r);
                        else
                            return read(r) - read(l-1);
                    }
                    
                    int read(int idx){
                        int sum = 0;
                        while(idx > 0){
                            sum += tree[idx];
                            idx -= (idx & -idx);
                        }
                        return sum;
                    }
                }
                public static boolean pal(String a){
                    int i=0;
                    int j=a.length()-1;
                    while(i<j){
                        if(a.charAt(i)!=a.charAt(j)){
                            return false;
                        }
                        i++;
                        j--;
                    }
                    return true;
                        
                }
                public static long find(long n,long k){
                    if(n==2){
                        if(k==1 || k==3)
                            return 1;
                        else
                            return 2;
                    }
                    long t=pow2(2,n,mod)-1;
                    long z=(t+1)/2;
                    if(k==z)
                        return n;
                    if(k<z)
                        return find(n-1,k);
                    else
                        return find(n-1,k-z);
                }
                public static long pow2(long a,long b,long mod){
                        long ans=1;
                        while(b>0){
                            if(b%2==1)
                                ans=(a*ans)%mod;
                            a=(a*a)%mod;
                            b/=2;
                        }
                        return  ans;
                }
                public static long pow3(long a,long b){
                        long ans=1;
                        while(b>0){
                            if(b%2==1)
                                ans=(a*ans);
                            a=(a*a);
                            b/=2;
                        }
                        return  ans;
                }
     
                 static class name implements Comparable<name> {
                    long l,b,h;
                    public name(long   x,long y,long z){
                        {
                            l=x;
                            b=y;
                        }
                        
                        
                        h=z;
                    }
                    public int compareTo(name o){
                        return -(int)(l*b-o.l*o.b);
                    }
                    
                }
                public static class s {
                    static BufferedReader reader;
                    static StringTokenizer tokenizer;
                
                    /** call this method to initialize reader for InputStream */
                    static void init(InputStream input) {
                        reader = new BufferedReader(
                                    new InputStreamReader(input) );
                        tokenizer = new StringTokenizer("");
                    }   
                
                    /** get next word */
                    static String ns() throws IOException {
                        while ( ! tokenizer.hasMoreTokens() ) {
                            //TODO add check for eof if necessary
                            tokenizer = new StringTokenizer(
                                reader.readLine() );
                        }
                        return tokenizer.nextToken();
                    }
                
                    static int ni() throws IOException {
                        return Integer.parseInt( ns() );
                    }
                
                    static double nd() throws IOException {
                        return Double.parseDouble( ns() );
                    }
                    static long nl() throws IOException {
                        return Long.parseLong( ns() );
                    }
                }
            }
                    
