from yogi import read, tokens

for n in tokens(int):
    mat = [[read(int) for _ in range(n)] for _ in range(n)]
    print("1" if is_symmetric(mat) else "0")

    q = read(int)
    for z in range(q):
        m = read(int)
        I: list[int] = []
        J: list[int] = []
        C: list[int] = []
        for k in range(0, m):
            i = read(int)
            j = read(int)
            v = read(int)
            I.append(i)
            J.append(j)
            C.append(mat[i][j])
            mat[i][j] = v

        print("1" if is_symmetric(mat) else "0")
        for k in range(0, m):
            mat[I[k]][J[k]] = C[k]
