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

i = A("i")
d = B("d")
f = A("f")
a = A("a")
l = B("l")
e = A("e")

i.z = e
d.r = l
f.z = a
a.z = e
l.r = d
e.z = a
assert i.z.z.z.z.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

i = A("i")
d = B("d")
f = A("f")
a = A("a")
l = B("l")
e = A("e")

i.z = e
d.r = l
f.z = a
a.z = e
l.r = d
e.z = a
assert i.z.z.z.z.txt == "a"