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

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

l = A("l")
e = B("e")
d = A("d")
h = B("h")
c = B("c")
b = A("b")

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

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

l = A("l")
e = B("e")
d = A("d")
h = B("h")
c = B("c")
b = A("b")

l.z = d
e.r = c
d.z = b
h.r = c
c.r = e
b.z = l
assert e.r.r.r.r.r.txt == "c"