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

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

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

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

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

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

d.q = i
d.z = i
e.s = i
i.s = e
l.q = e
l.z = e
h.q = e
h.z = i
assert h.z.s.s.s.s.txt == "i"