提示: 欢迎访问OurACM平台。
Problem 1511 Score Statistics

Accept: 104    Submit: 464
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

Oaiei hates math, because math problems are most likely to be wrong. You may forget the formula, have wrong intermediate results, spell wrong letters or some are left blank, all these will be judged wrong answer by the teacher.

A math problem can usually fall into several parts, and each part is dependent on answers of previous parts. So if you got the wrong answer in some previous part, the teacher will not see the rest, even if you have written over the entire paper.

Now, the teacher asks you to help write a program automatically calculating oaiei’s results in mathematics, so can you work it out?

The teacher gives statistics in the following format:

  • Ti bi A        indicate that the bi part of the Ti question is right
  • Tj bj W        indicate that the bj part of the Tj question is wrong

Those parts the teacher didn’t mention imply oaiei didn’t answer it.

Input


The input contains several datasets. For each dataset, the first line has three integers N, M, S (1<=N<=100000, 1<=M<=100000). N indicates the number of math question, questions are numbered from 1 to N; M indicates the number of statistical data the teacher gives you; S indicates scores for each part of a question. Line 2 to N +1, each line has an integer d (1<=d<=100000) indicating that the corresponding question has d parts. Line N + 2 to N + M + 1, one statistics per line. Each statistics consists of two integers t, b and one character c, which means the result of b part of the t question is c, (c can only be ‘A’ or ‘W’). We guarantee that all data are consistent.

Output


oaiei’ final scores for this math test.

Sample Input

2 3 1 2 3 1 2 A 1 1 W 2 1 A

Sample Output

1

Source

FOJ月赛-2007年6月

Submit  Back  Status  Discuss