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

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

c = A("c")
m = B("m")
d = A("d")

c.t = m
m.r = d
d.t = m
assert m.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

c = A("c")
m = B("m")
d = A("d")

c.t = m
m.r = d
d.t = m
assert m.r.t.r.txt == "d"