class A:
    def __init__(self, txt: str):
        self.s: B = 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.z: B = None
        self.w: A = None
        self.txt = txt

k = A("k")
m = B("m")
n = C("n")
b = C("b")
h = A("h")
d = A("d")
a = C("a")

k.s = m
m.x = k
n.z = m
n.w = h
b.z = m
b.w = h
h.s = m
d.s = m
a.z = m
a.w = d
assert m.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = 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.z: B = None
        self.w: A = None
        self.txt = txt

k = A("k")
m = B("m")
n = C("n")
b = C("b")
h = A("h")
d = A("d")
a = C("a")

k.s = m
m.x = k
n.z = m
n.w = h
b.z = m
b.w = h
h.s = m
d.s = m
a.z = m
a.w = d
assert m.x.s.x.s.txt == "m"