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.
The first line contains three integers *a*, *b* and *c* (0 ≤ *a*, *b*, *c* ≤ 10<sup class="upper-index">5</sup>)  — 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·10<sup class="upper-index">5</sup>)  — the number of mouses in the price list.

The next *m* lines each describe another mouse. The *i*-th line contains first integer *val*<sub class="lower-index">*i*</sub> (1 ≤ *val*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>)  — the cost of the *i*-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
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.
2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2
3 14
1 4 4
12
36949214 USB
683538043 USB
595594834 PS/2
24951774 PS/2
131512123 USB
327575645 USB
30947411 USB
916758386 PS/2
474310330 USB
350512489 USB
281054887 USB
875326145 USB
8 2345344274
3 0 3
0
0 0
1 2 4
12
257866589 PS/2
246883568 USB
104396128 USB
993389754 PS/2
896419206 USB
405836977 USB
50415634 PS/2
152940828 PS/2
847270779 PS/2
850467106 USB
922287488 USB
622484596 PS/2
7 1840824320
0 4 2
12
170189291 USB
670118538 USB
690872205 PS/2
582606841 PS/2
397508479 USB
578814041 USB
96734643 USB
168371453 USB
528445088 PS/2
506017602 PS/2
512143072 USB
188740735 USB
6 2573047832
5 100 100
29
741703337 USB
285817204 PS/2
837154300 USB
250820430 USB
809146898 PS/2
10478072 USB
2833804 PS/2
669657009 USB
427708130 PS/2
204319444 PS/2
209882040 USB
56937335 USB
107442187 USB
46188465 USB
902978472 USB
792812238 PS/2
513787720 PS/2
486353330 PS/2
168930159 PS/2
183624803 USB
67302934 USB
264291554 USB
467936329 USB
82111533 USB
849018301 USB
645374374 PS/2
967926381 PS/2
286289663 PS/2
36760263 USB
29 11375586709
71 15 60
24
892757877 USB
613048358 USB
108150254 USB
425313488 USB
949441992 USB
859461207 PS/2
81440099 PS/2
348819522 USB
606267503 USB
443620287 PS/2
610038583 USB
374259313 PS/2
947207567 PS/2
424889764 PS/2
58345333 USB
735796912 PS/2
523115052 USB
983709864 USB
426463338 USB
305759345 PS/2
689127461 PS/2
878781173 PS/2
445036480 USB
643765304 USB
24 13374616076
37 80 100
31
901706521 USB
555265160 PS/2
547038505 PS/2
644436873 PS/2
105558073 USB
915082057 PS/2
913113815 USB
953413471 PS/2
252912707 PS/2
830344497 USB
781593007 USB
610659875 PS/2
177755858 PS/2
496444729 PS/2
617569418 USB
304908147 PS/2
188649950 PS/2
705737216 USB
473915286 USB
622994426 PS/2
783873493 USB
789927108 USB
258311181 PS/2
720083354 PS/2
676406125 PS/2
634885851 PS/2
126814339 USB
704693540 USB
789707618 PS/2
938873907 USB
576166502 USB
31 18598842609
6 100 10
11
931138340 USB
421397130 USB
899599243 PS/2
891033726 PS/2
375251114 PS/2
991976657 USB
743116261 PS/2
163085281 PS/2
111524953 PS/2
148832199 PS/2
480084927 PS/2
11 6157039831
1 1 124
1
2 USB
1 2
1 1 1
3
3 USB
3 PS/2
3 PS/2
3 9
3 3 3
6
3 USB
3 USB
3 USB
3 USB
3 USB
3 USB
6 18
1 1 1
0
0 0
1 1 1
4
9 USB
1 PS/2
5 USB
6 PS/2
3 12
1 1 1
1
6 PS/2
1 6
1 3 1
5
1 PS/2
8 USB
8 PS/2
8 PS/2
1 PS/2
5 26
3 2 1
6
1 USB
4 PS/2
4 PS/2
7 USB
8 PS/2
1 USB
6 25
1 1 1
3
10 USB
6 USB
6 USB
2 12
1 1 1
3
4 USB
3 PS/2
3 USB
3 10
1 1 1
2
6 PS/2
5 USB
2 11
1 1 2
5
4 USB
7 PS/2
10 PS/2
7 PS/2
3 USB
4 21
1 4 4
8
36949214 USB
683538043 USB
595594834 PS/2
24951774 PS/2
131512123 USB
327575645 USB
30947411 USB
474310330 USB
7 1621841331
1 4 4
9
36949214 USB
683538043 USB
595594834 PS/2
24951774 PS/2
131512123 USB
327575645 USB
30947411 USB
916758386 PS/2
474310330 USB
8 2538599717
1 4 4
10
36949214 USB
683538043 USB
595594834 PS/2
24951774 PS/2
131512123 USB
327575645 USB
30947411 USB
916758386 PS/2
474310330 USB
350512489 USB
8 2414801876
48810 78876 100000
0
0 0
1 0 0
1
862644246 PS/2
0 0
2 6 0
3
380521935 USB
261865233 USB
744434239 USB
2 642387168
0 0 0
1
1 USB
0 0
0 0 0
1
2 USB
0 0
1 1 1
1
5 USB
1 5
1 1 1
2
2 USB
5 USB
2 7
1 1 1
2
3 PS/2
6 PS/2
2 9
2 1 1
4
5 USB
5 PS/2
3 PS/2
7 PS/2
3 13
t=1
while t>0:
    t-=1
    a,b,c=(int(_) for _ in input().strip().split(' '))
    n=int(input())
    u=[]
    p=[]
    cnt1=0
    cnt2=0
    for i in range(n):
        x=int(input().split(' '))
        s=input()
        if s=="USB":
            u.append(x)
            cnt1+=1
        if s=="PS/2":
            p.append(x)
            cnt2+=1
    u.sort()
    p.sort()
    ans=min(a,cnt1)+min(b,cnt2)+min(c,max(cnt1-a,0)+max(cnt2-b,0))
    val=0
    for i in range(min(a,cnt1)):
        val+=u[i]
    for i in range(min(b,cnt2)):
        val+=p[i]
    pos1=min(a,cnt1)
    pos2=min(b,cnt2)
    while c!=0:
        if cnt1-a>0 and cnt2-b>0:
            if u[pos1]<=p[pos2]:
                val+=u[pos1]
                pos1+=1
            else:
                val+=p[pos2]
                pos2+=1
        else:
            if cnt1-a>0:
                val+=u[pos1]
                pos1+=1
            if cnt2-b>0:
                val+=p[pos2]
                pos2+=1
            if cnt1-a<=0 and cnt2-b<=0:
                break
    print(ans,end=' ')
    print(val)