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

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

d = A("d")
e = B("e")
l = B("l")
m = B("m")
h = A("h")

d.o = l
e.q = m
e.z = h
l.q = m
l.z = h
m.q = e
m.z = h
h.o = m
assert e.z.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

d = A("d")
e = B("e")
l = B("l")
m = B("m")
h = A("h")

d.o = l
e.q = m
e.z = h
l.q = m
l.z = h
m.q = e
m.z = h
h.o = m
assert e.z.o.q.txt == "e"