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

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

l = A("l")
f = B("f")
h = A("h")

l.s = f
f.z = l
f.r = h
h.s = f
assert h.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

l = A("l")
f = B("f")
h = A("h")

l.s = f
f.z = l
f.r = h
h.s = f
assert h.s.z.s.txt == "f"