def matrix_to_string(matrix):
    """Format the QR matrix as a string."""

    lines = []
    qrsize = matrix.shape[0]
    for y in range(qrsize):
        s = []
        for x in range(qrsize):
            if matrix[y, x] == 0:
                s.append(".")
            elif matrix[y, x] == 1:
                s.append("X")
            else:
                s.append("?")
        lines.append("  " + " ".join(s))
    return "\n".join(lines)