Rock Paper Scissors
题号:NC222751
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

BaoBao and DreamGrid are playing a card game. Each player has cards in the beginning and there are three types of cards: rock, paper, and scissors.

The game consists of rounds. In each round, BaoBao will first play one of his remaining cards (this card is shown to both players). After that, DreamGrid can choose one of his remaining cards and play it (also shown to both players). The score of this round is calculated by referring to the following table:

After the round, the two played cards are removed from the game. The score of the whole game is the sum of the score of each round.

BaoBao aims at minimizing the score of the whole game, while DreamGrid aims at maximizing it. Both players know the number of cards of each type his opponent and himself holds in the beginning. What's the final score of the game given that both of them take the best strategy?

输入描述:

There are multiple test cases. The first line of the input contains an integer  () indicating the number of test cases. For each test case:
The first line contains three integers b_r, b_p and b_s (), indicating the number of rock, paper and scissors cards BaoBao has.
The second line contains three integers d_r, d_p and d_s (), indicating the number of rock, paper and scissors cards DreamGrid has.
It's guaranteed that .

输出描述:

For each test case output one line containing one integer indicating the final score of game.
示例1

输入

复制
4
4 4 2
10 0 0
0 10 0
2 4 4
1 2 3
3 2 1
10 10 10
10 10 10

输出

复制
-2
2
5
30