for _ in range(int(input())):
    a, b, c, d = map(str, input().split())
    e, f, g, h = map(str, input().split())
    i, j, k, x = map(str, input().split())
    m, n, o, p = map(str, input().split())

    print(a + " " + b + " " + c + " " + d + " " + h + " " + x + " " + p + " "
          + o + " " + n + " " + m + " " + i + " " + e + " " + f + " " + g + " " + k + " " + j)
