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

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

n = A("n")
d = B("d")
h = B("h")

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

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

n = A("n")
d = B("d")
h = B("h")

n.o = h
d.z = n
d.p = n
h.z = n
h.p = n
assert h.z.o.z.txt == "n"