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

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

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

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

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

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

b.z = a
m.s = b
a.s = b
assert b.z.s.z.txt == "a"