# https://yukicoder.me/problems/no/3596 def same_line(h0, w0, h1, w1): if h0 == h1 or w0 == w1: return True elif h0 - w0 == h1 - w1: return True elif h0 + w0 == h1 + w1: return True return False def solve(H, W, A): for index0 in range(H * W): for index1 in range(index0 + 1, H * W): h0 = index0 // W w0 = index0 % W h1 = index1 // W w1 = index1 % W if same_line(h0, w0, h1, w1): a0 = A[h0][w0] a1 = A[h1][w1] v = a0 + a1 if v > 0: return "infinite" return "finite" def main(): T = int(input()) answers = [] for _ in range(T): H, W = map(int, input().split()) A = [] for _ in range(H): A.append(list(map(int, input().split()))) ans = solve(H, W, A) answers.append(ans) for ans in answers: print(ans) if __name__ == "__main__": main()