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

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

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

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

m.s = d
e.x = m
k.w = e
d.s = m
assert k.w.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

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

m.s = d
e.x = m
k.w = e
d.s = m
assert k.w.x.s.txt == "d"