CF1701A.Grass Field

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Grass Field

There is a field of size 2×22 \times 2. Each cell of this field can either contain grass or be empty. The value ai,ja_{i, j} is 11 if the cell (i,j)(i, j) contains grass, or 00 otherwise.

In one move, you can choose one row and one column and cut all the grass in this row and this column. In other words, you choose the row xx and the column yy, then you cut the grass in all cells ax,ia_{x, i} and all cells ai,ya_{i, y} for all ii from 11 to 22. After you cut the grass from a cell, it becomes empty (i. e. its value is replaced by 00).

Your task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all ai,ja_{i, j} zeros).

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t161 \le t \le 16) — the number of test cases. Then tt test cases follow.

The test case consists of two lines, each of these lines contains two integers. The jj-th integer in the ii-th row is ai,ja_{i, j}. If ai,j=0a_{i, j} = 0 then the cell (i,j)(i, j) is empty, and if ai,j=1a_{i, j} = 1 the cell (i,j)(i, j) contains grass.

Output

For each test case, print one integer — the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all ai,ja_{i, j} zeros) in the corresponding test case.

Samples

3
0 0
0 0
1 0
0 1
1 1
1 1
0
1
2

在线编程 IDE

建议全屏模式获得最佳体验