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

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

f = A("f")
b = B("b")
k = B("k")
a = A("a")

f.z = k
b.r = k
k.r = b
a.z = k
assert a.z.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

f = A("f")
b = B("b")
k = B("k")
a = A("a")

f.z = k
b.r = k
k.r = b
a.z = k
assert a.z.r.r.r.txt == "b"