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

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

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

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

i.t = m
i.w = d
m.y = i
k.y = m
d.y = i
assert m.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.txt = txt

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

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

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

i.t = m
i.w = d
m.y = i
k.y = m
d.y = i
assert m.y.w.y.txt == "i"