Little Q is testing a self-designed puzzle game involving a $$$2 \times 2$$$ grid where each cell can either be on or off. When a cell is toggled, its state changes from off to on or from on to off. The following four operations can be performed at a certain cost:
Little Q has realized that the game has started, but the screen somehow malfunctions, blocking him from seeing the current state of any cell. The only feedback he can receive is a special prompt sound triggered if, after an operation, all cells are on.
Knowing all $$$m$$$ possible initial grids of the game in advance, Little Q wants to find a sequence of operations, ensuring that regardless of the initial grid when he starts playing, he will always hear the prompt sound after some operations in the order of the sequence.
Please calculate the minimum total cost of such sequence of operations.
The first line of the input contains five integers $$$T$$$ ($$$1 \le T \le 10^4$$$), $$$a_0$$$, $$$a_1$$$, $$$a_2$$$, and $$$a_3$$$ ($$$1 \le a_0,a_1,a_2,a_3 \le 10^6$$$), indicating the number of games and the costs of each operation. For each game:
The first line contains an integer $$$m$$$ ($$$1 \le m \le 16$$$), indicating the number of possible initial grids of the game.
Then $$$m$$$ grids follow. For each grid:
It is guaranteed that the given grids in a game are pairwise different.
For each game, output a line containing an integer, indicating the minimum total cost.
2 1000 100 10 14100001000010000111111
1121 2