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

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

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

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

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

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

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

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

a.x = k
d.p = h
d.s = h
m.x = a
m.u = h
m.w = k
h.p = d
h.s = d
k.x = a
assert m.w.x.x.txt == "k"