You will be given two Bipartite Graphs, each with N vertices. The vertices in both the graphs are labeled from 1 to N.
You have to find the maximum size of a set S of vertices, such that it forms an Independent Set in the first graph, and the subgraph induced by S in the second graph has a perfect matching.
Input Format
The first line will contain an integer T, denoting the number of test cases that follow.
For each of the test cases, the first line will contain an integer N denoting the number of vertices in the two graphs
The next N lines will contain N integers each, denoting the adjacency matrix of the first graph. The value in the row will represent the value of , and it is guaranteed that each value of is either 0 or 1, and .
The next N lines will again contain N integers each, this time denoting the adjacency matrix of the second graph, in a similar fashion as .
It is guaranteed that and both and represent adjacency matrices of a bipartite graph.
Output Format
For every test case, output the maximum size of the set S.
Constraints
The two graphs from the sample are shown below. Note that you cannot pick a set S of size greater than 2.
One such set S is since it forms an independent set in Graph A and the subgraph induced by forms a perfect matching in Graph B