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

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

a = A("a")
b = B("b")
n = B("n")

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

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

a = A("a")
b = B("b")
n = B("n")

a.r = n
b.z = n
n.z = b
assert a.r.z.z.txt == "n"