FreeOpen is an organization which arranges blind data for girls and boys. The moral of that name is “Open your free mind to find your other half”. FreeOpen use a pet to make a match to a girl and a boy. FreeOpen believe that if a girl and a boy like each other and they like the same pet, they will be happy when they are living together with that pet.
There are n boys, m girls and k pets. FreeOpen want know the maximum matches. Each match consists of one girl, one boy and one pet, and each girl, boy or pet can only be in one single match.
The first line consists of an integer T, indicating the number of test cases.
The first line of each case consists of three integers G, B, P, indicating the number of girls, the number of boys and the number of pets. The next G * B matrix indicates whether a girl and a boy like each other. The i-th girl and j-th boy like each other if and only if Matrix (i, j) = 1; the next G * P matrix indicates whether a girl likes a pet and the next B * P matrix indicates whether a boy likes a pet.
Output the maximum matches on a single line for each test case.
0 < T <= 10
0 < G, B, P <= 20
0 < G + B + P <= 60