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

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

l = A("l")
c = B("c")
e = A("e")
m = A("m")
b = B("b")

l.q = m
c.z = m
c.q = l
e.q = l
m.q = l
b.z = m
b.q = l
assert e.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

l = A("l")
c = B("c")
e = A("e")
m = A("m")
b = B("b")

l.q = m
c.z = m
c.q = l
e.q = l
m.q = l
b.z = m
b.q = l
assert e.q.q.q.q.txt == "m"