class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

c = A("c")
n = B("n")
m = A("m")

c.o = m
c.z = n
n.p = c
m.o = c
m.z = n
assert n.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

c = A("c")
n = B("n")
m = A("m")

c.o = m
c.z = n
n.p = c
m.o = c
m.z = n
assert n.p.z.p.txt == "c"