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

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

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

m = A("m")
n = B("n")
j = C("j")

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

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

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

m = A("m")
n = B("n")
j = C("j")

m.t = n
m.r = n
n.r = m
j.t = n
assert m.r.r.r.txt == "n"