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

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

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

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

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

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

l.z = d
j.q = d
d.q = j
m.z = j
h.z = j
assert m.z.q.q.q.q.txt == "j"