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.
//package practice_problems;

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

/**
 *
 * @author Tushar Jan 30, 2017
 */
public class B_762_new {

    long mod = 1000000007;
    public static class Mouse{
        int value;
        int type;
        public Mouse(int a,int b){
            value=a;
            type=b;
        }
        
    }
    
    public static class AscendingComparator implements Comparator<Mouse>{
        @Override
        public int compare(Mouse o1, Mouse o2) {
            if(o1.value< o2.value) return -1;
            else if(o1.value>o2.value) return 1;
            else return 0;
            
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
        
    }

    public static final int USB=0,PS2=1;
    public static void main(String args[])
    {
        InputReader in = new InputReader(System.in);
        PrintWriter out= new PrintWriter(System.out);

        int t=1;
        while(t-->0)
        {
            int a=in.nextInt();
            int b= in.nextInt();
            int c= in.nextInt();
            
            int m=in.nextInt();
            
            List<Mouse> list=new ArrayList<>();
            
            for(int i=0;i<m;i++){
                int cost=in.nextInt();
                String type=in.next();
                Mouse mouse= new Mouse(cost,type.equalsIgnoreCase("USB")?USB:PS2);
                list.add(mouse);
            }
            
            Collections.sort(list,new AscendingComparator());
            
//            for(int i=0;i<list.size();i++){
//                out.println(list.get(i).value+"--"+list.get(i).type);
//            }
            int count=0;long minval=0L;
            
            for(int i=0;i<m;i++)
            {
                int cost=list.get(i).value;
                int type=list.get(i).type;
                
                if(type==USB){
                    if(a>0){
                        --a;
                        ++count;
                        minval+=cost;
                    }
                    else if(c>0){
                        --c;
                        ++count;
                        minval+=cost;
                    }
                }
                else
                {
                    if(b>0){
                        --b;
                        ++count;
                        minval+=cost;
                    }
                    else if(c>0){
                        --c;++count;
                        minval+=cost;
                    }
                }
                    
            }
            out.print(count+" "+minval);
            
        }

        out.flush();
        out.close();


    }



    long power(long x, long n) {
        if (n <= 0) {
            return 1;
        }
        long y = power(x, n / 2);
 
        if ((n & 1) == 1) {
            return (((y * y) % mod) * x) % mod;
        }
 
        return (y * y) % mod;
    }
 
    public long gcd(long a, long b) {
        a = Math.abs(a);
        b = Math.abs(b);
        return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).longValue();
    }
    
    
    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 String next() {
            return readString();
        }
 
        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);
        }
    }

}
