def merge_func(m1: cirq.Moment, m2: cirq.Moment) -> Optional[cirq.Moment]:

    def is_z_moment(m):
        return all(((op.gate == cirq.Z) for op in m))
    if (not (is_z_moment(m1) and is_z_moment(m2))):
        return None
    qubits = (m1.qubits | m2.qubits)

    def mul(op1, op2):
        return ((op1 or op2) if (not (op1 and op2)) else cirq.decompose_once((op1 * op2)))
    return cirq.Moment((mul(m1.operation_at(q), m2.operation_at(q)) for q in qubits))
def merge_func(m1: cirq.Moment, m2: cirq.Moment) -> Optional[cirq.Moment]:

    def is_z_moment(m):
        return all(((op.gate == cirq.Z) for op in m))
    if (not (is_z_moment(m1) and is_z_moment(m2))):
        return None
    qubits = (m1.qubits | m2.qubits)

    def mul(op1, op2):
        return ((op1 or op2) if (not (op1 and op2)) else cirq.decompose_once((op1 * op2)))
    return cirq.Moment((mul(m1.operation_at(q), m2.operation_at(q)) for q in qubits))