7609: Tic-Tac-Toe-Nim

内存限制:128 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Alice and Bob are playing a new game that is a mixture of tic-tac-toe and nim.
There are 9 piles of stones forming a 3∗3 grid. Players take turns to remove the stones: in each turn, the player choose a remaining pile and remove a positive number of stones from it. Alice goes first. The first player to remove a pile so that a new empty row or column is formed wins. Notice that player does NOT have to be the one to remove all three piles to win, and diagonals does NOT count as a win.
However, to speed up the game, both players have decided they will always remove the whole pile they choose in their respective first turn, instead of removing only part of the pile. Now Alice wants to know how many different moves can she choose in the first turn so that she can still ensure her victory.
 

输入格式

The first line contains one integer T (1≤T≤500000), the number of test cases.
For each test case, there are 3 lines, each contains 3 integers aij (1≤aij≤109), denoting the number of stones in each pile.

输出格式

For each test case, output one integer denoting the answer. Output 0 when Alice can not win in the situation.

输入样例 复制

2
1 1 1
1 1 1
1 1 1
1 2 3
4 5 6
7 8 9

输出样例 复制

9
7