E. Course Selection
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The cultivation of UESTC master's students adopts a combination of coursework and thesis research. Through coursework and thesis research, students systematically master the theoretical knowledge in their discipline and develop problem-solving abilities.

The total credits for a master's degree are divided into two parts: course credits and compulsory sessions. Courses in course credits are divided into two categories: degree courses and non-degree courses. Degree courses include public foundational courses and professional foundational courses. Non-degree courses include professional elective courses, interdisciplinary elective courses, and other elective courses.

To complete the program, students must meet the following credit requirements:

  • The total credits must be no less than $$$a$$$.
  • The total course credits must be no less than $$$b$$$.
  • Credits for the compulsory sessions must be no less than $$$c$$$.
  • Credits for the degree courses must be no less than $$$d$$$, and at least one public foundational course must be taken.
  • Credits for the professional courses, including professional foundational courses and professional elective courses, must be no less than $$$e$$$.
  • Credits for the professional foundational courses must be no less than $$$f$$$.
  • Credits for the professional elective courses must be no less than $$$g$$$ credits.

Now, given a course selection plan, including the course names, course types, and credits for each course, please determine if the plan meets the credit requirements.

Input

The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), indicating the number of test cases.

The first line of each test case contains seven integers $$$a,b,c,d,e,f,g$$$ ($$$1 \leq a,b,c,d,e,f,g \leq 100$$$, $$$a \geq b+c$$$, $$$b \geq d \gt f$$$, $$$b \geq e \geq f+g$$$), the meanings of which are described above.

The second line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$), indicating the number of selected courses.

The following $$$3n$$$ lines describe the $$$n$$$ courses, with each course occupying three lines. The first line contains the course name with a maximum length of $$$50$$$, consisting of only English letters and spaces. All the course names are different from others, and spaces will not appear at the beginning and the end of the names. The second line contains the course type, which is one of public foundational courses, professional foundational courses, professional elective courses, interdisciplinary elective courses, other elective courses, and compulsory sessions. The third line contains an integer representing the course credit, ranging within $$$[1,10]$$$.

Output

For each test case, output $$$\texttt{YES}$$$ in a single line if the plan meets the credit requirements, otherwise output $$$\texttt{NO}$$$ in a single line.

Example
Input
1
28 24 4 15 15 6 7
15
Socialism with Chinese Characteristics
public foundational courses
2
Matrix Theory
professional foundational courses
3
Optimization Theory
professional foundational courses
3
Communication Network Theory
professional elective courses
2
Bayesian Learning and Random Matrix
professional elective courses
2
Image and Video Processing
professional foundational courses
2
Graph Theory
professional foundational courses
3
Machine Learning
professional elective courses
2
Visual Data Analysis
professional elective courses
2
Guidance on Writing Graduate Thesis
other elective courses
1
Graduate English
public foundational courses
3
Teaching Practice
compulsory sessions
1
Academic Activities
compulsory sessions
1
General Education Elective Courses
compulsory sessions
1
Academic Exchange
compulsory sessions
1
Output
YES