| Soy Cup #2: Vivian |
|---|
| Finished |
Since they cannot find the third and fourth players, Diluc and Kaeya are playing a simplified version of contract bridge with only two players. A full deck of 52 cards is evenly split into two visible hands. Each player is randomly and independently marked as vulnerable or not.
Then, they start to bid the contract in turn, with Diluc bidding first. Players bid in turn, starting with Diluc. A bid is a contract consisting of a level (1–7) and a suit from the following hierarchy: C < D < H < S < N (No Trump). A bid can only be made if it outranks the current highest bid — that is, it has a higher level, or the same level with a higher suit. For example, if Diluc has bid 1H, Kaeya can bid 1S, 1N, or 2C, but he cannot bid 1C or 1H itself. Either player may pass. If both pass consecutively, bidding ends. The last bidder becomes the declarer, and the other becomes the defender.
The declarer must win at least $$$x+6$$$ tricks, where $$$x$$$ is the contract level. After all cards are played, the score is calculated. The declarer gains points if the contract is fulfilled; otherwise, the defender gains points. The total score is always zero-sum.
Let $$$x$$$ be the contract level, and $$$y$$$ be the number of extra tricks ($$$y \gt 0$$$ if over, $$$y \lt 0$$$ if under):
For example, if Diluc is not vulnerable, declares 6N and wins $$$13$$$ tricks, he will win $$$(30\times6+10)+300+30+500=1020$$$ points. If Kaeya is vulnerable, declares 4S and wins $$$4$$$ tricks, he will lose $$$300\times(10-4)-100=1700$$$ points.
Specifically, if neither bids a contract during the bidding, neither of them gains score.
Both players are perfect analysts: they know exactly how many tricks they can win as declarer with each suit. Given this, bidding proceeds optimally for both sides to maximize their expected score. They are now tired of playing cards and want to know their score as long as the cards are assigned. Because double-dummy analysis is very complex, they will tell you the results and expect you to calculate the final score within 1 second.
Each test contains multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains two integers $$$v_1,v_2$$$ $$$(0\le v_1,v_2\le1)$$$ — vulnerability of Diluc and Kaeya ($$$1$$$ means vulnerable).
The second line of each test case contains five integers $$$c_1,d_1,h_1,s_1,n_1$$$ $$$(0\le c_1,d_1,h_1,s_1,n_1\le13)$$$ — the number of tricks Diluc can win as declarer with each suit C, D, H, S, and N.
The third line of each test case contains five integers $$$c_2,d_2,h_2,s_2,n_2$$$ $$$(0\le c_2,d_2,h_2,s_2,n_2\le13)$$$ — the same numbers for Kaeya.
It is guaranteed that each test case corresponds to a valid double dummy analysis with a consistent deal.
For each test case, output one integer — the final score Diluc gets, assuming both play optimally.
60 09 11 13 6 93 2 0 7 30 19 11 13 6 93 2 0 7 30 09 6 7 3 54 6 5 10 61 04 5 2 4 29 8 11 9 110 15 5 7 6 58 8 6 6 50 110 7 9 5 53 6 3 8 8
1400 1510 -300 -460 -90 140
In the first sample case, the optimal contract is 7S declared by Kaeya.
In the second sample case, the optimal contract is 7H declared by Diluc.
| Name |
|---|


