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

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

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

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

a.w = d
k.p = b
n.x = k
l.w = n
d.x = k
b.w = d
h.x = k
assert k.p.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

a.w = d
k.p = b
n.x = k
l.w = n
d.x = k
b.w = d
h.x = k
assert k.p.w.x.txt == "k"