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.txt = txt

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

f.t = m
a.s = m
m.t = f
assert m.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.txt = txt

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

f.t = m
a.s = m
m.t = f
assert m.t.t.t.txt == "f"