Cup of Cowards

No attempts yetTime limit3sMemory limit128 MB

Problem

Cup of Cowards (CoC) is a role playing game with five character classes: mage, tank, fighter, assassin and marksman. A team is five players, one of each class, and their goal is to kill a monster with LL life points. The monster dies once the total damage it has taken is at least LL.

Every character may hit only a limited number of times. All hits of one character deal the same damage and cost the same amount, but the damage and the cost may differ from character to character. The team wants to pay as little as possible so they do better in later missions. Find the minimum cost the team pays to kill the monster, and the damage they deal to it.

Input

The first line has one integer TT, the number of test cases (1T1001 \le T \le 100).

The first line of each test case has one integer LL, the life points of the monster (0L10120 \le L \le 10^{12}). Five lines follow, one per character, each with three integers HH, DD and CC separated by single spaces: the maximum number of hits, the damage of one hit and the cost of one hit (0H10000 \le H \le 1000, 0D,C1090 \le D, C \le 10^9). The five values of HH add up to at most 10001000.

Output

For each test case print one line with two integers separated by a space. The first is the minimum cost of the hits that kill the monster, the second is the damage those hits deal. If several plans reach the minimum cost, choose the one that deals the least damage. When LL is 00 the team needs no hit, so print 0 0. If no set of hits can kill the monster, print We are doomed!!.