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

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

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

a.t = b
f.s = b
f.w = a
b.t = a
assert a.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

a.t = b
f.s = b
f.w = a
b.t = a
assert a.t.t.t.txt == "b"