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.r: B = None
        self.txt = txt

j = A("j")
l = B("l")
a = A("a")
c = B("c")
e = B("e")

j.q = a
l.z = j
l.r = c
a.q = j
c.z = j
c.r = e
e.z = j
e.r = l
assert j.q.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.r: B = None
        self.txt = txt

j = A("j")
l = B("l")
a = A("a")
c = B("c")
e = B("e")

j.q = a
l.z = j
l.r = c
a.q = j
c.z = j
c.r = e
e.z = j
e.r = l
assert j.q.q.q.q.q.txt == "a"