F. Fair Gambling
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

As a student at National Taiwan University (NTU), you are faced with countless gambles — both big and small — even before you officially enroll. The very process of getting into NTU is a gamble in itself. No matter which admission route you take, there's no guarantee you won't have bad luck and encounter questions that don't play to your strengths, or underperform in a crucial exam or competition.

After entering the university, you'll continue to face gambles. For example, course selection is like a strategic game. Whether you can successfully enroll in the courses you want, whether a course is cold or sweet, and whether the grading is fair — these are all uncertainties you must carefully navigate.

Although these gambles are games with incomplete information and a lot of randomness, there are still ways to minimize your risks and losses. The best strategy is to gather as much information as possible and use it wisely in your decision-making. For instance, before course selection, you can research course reviews to avoid those with heavy workloads and stingy grading or ones where no one seems to understand what's going on. You can also investigate how much effort each course typically demands, allowing you to manage your semester in a way that's not too stressful, yields good grades, and still helps you learn something meaningful.

To that end, students have developed a unique set of terms for evaluating courses, such as:

  • Sweet: The course gives out generous grades; most people can earn high marks.
  • Cold: The course doesn't require much effort.
  • Hard: The course requires a lot of effort or is very difficult — for example, heavy assignments, tough exams, and other demanding aspects make a course considered hard.
  • Solid-sweet: Although getting a high grade isn't exactly easy, putting in sufficient effort almost guarantees a good result.

There can be disagreements when evaluating whether a course is truly sweet or cold, since each person has different expectations — some are satisfied just by passing, while others won't settle for less than an A+. Everyone has different abilities too, so the effort required and the difficulty of earning good grades can vary widely.

When collecting course information, it's also possible to receive misinformation — that's all part of the gamble too! You might come across outdated reviews from years ago, and the course may have changed significantly since then. Or perhaps the reviewer was exceptionally talented and breezed through every course with ease, leading you to mistakenly believe a brutally difficult course is both cold and sweet, only to suffer through it yourself.

For example, if someone tells you that the course Programming Techniques is cold and sweet, you might want to be skeptical.

To avoid being misled, you carefully study the rules and workload of Programming Techniques and discover something called a summer assignment. "Oh no, I haven't done a summer assignment since junior high school," some might think. Wanting to protect your well-earned summer vacation, you manage to acquire insider information that the summer assignment contains $$$N$$$ problems, and for each problem, it's sufficient if any one of your three team members solves it. This means you can strategically distribute the workload to ensure everyone gets to enjoy their summer.

However, things aren't that simple. Just like how the sweetness or coldness of a course can feel different depending on the person, for your team of three, the effort required to solve each problem also varies by person. The effort required for the $$$i$$$-th person to solve the $$$j$$$-th problem is denoted as $$$c_{i,j}$$$, and the total effort that the $$$i$$$-th person can put into the summer assignment cannot exceed $$$p_i$$$ — otherwise, they'll find the course too hard and quit the team.

Fortunately, you don't have to worry too much. The teaching assistants are kind, so you don't need to solve all the problems in the assignment to get full marks.$$$^{\text{∗}}$$$ However, the one piece of information you can't obtain is how many problems need to be solved to earn full credit. Until the assignment is officially released, this number remains unknown.

Therefore, you want to compute in advance: What is the maximum number of problems your team can solve, given each person's effort limit?

Note: Each problem only needs to be solved by one team member to count as completed. Even if two people solve the same problem, it only counts once. Since the majority of the effort for a problem falls on the person solving it, you can assume that each problem your team wants to solve is assigned to exactly one person. If the $$$i$$$-th person is assigned the $$$j$$$-th problem, they must spend $$$c_{i,j}$$$ effort to complete it.

$$$^{\text{∗}}$$$This is not guaranteed in the real world.

Input

The first line contains an integer $$$T$$$, representing the number of test cases.

For each test case, the first line contains four integers: $$$N$$$, $$$p_1$$$, $$$p_2$$$, and $$$p_3$$$, representing the number of problems in the summer assignment and the effort limits of the three team members.

The next three lines each contain $$$N$$$ integers. The $$$i$$$-th of these lines contains $$$c_{i,1}, c_{i,2}, \dots, c_{i,N}$$$, representing the amount of effort the $$$i$$$-th person needs to spend to solve each of the $$$N$$$ problems.

  • $$$1 \leq T \leq 200$$$
  • $$$1 \leq N \leq 200$$$
  • $$$1 \leq p_1,p_2,p_3 \leq 500$$$
  • $$$1 \leq c_{i,j} \leq 500$$$
  • It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$200$$$.
Output

For each test case, output a single line containing one integer representing the maximum number of problems your team can solve.

Example
Input
2
5 4 9 3
1 3 2 5 4
3 2 4 5 1
1 4 3 2 3
5 4 4 1
1 3 2 5 4
3 2 4 5 1
1 4 3 2 3
Output
5
4