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

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

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

m = A("m")
k = B("k")
d = C("d")
n = B("n")

m.t = n
m.y = d
k.r = d
d.x = m
d.y = m
d.t = n
n.r = d
assert n.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: C = None
        self.txt = txt

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

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

m = A("m")
k = B("k")
d = C("d")
n = B("n")

m.t = n
m.y = d
k.r = d
d.x = m
d.y = m
d.t = n
n.r = d
assert n.r.t.r.txt == "d"