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

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

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

c = A("c")
k = B("k")
d = C("d")
f = C("f")
n = A("n")
a = C("a")
i = B("i")
h = C("h")

c.w = h
k.r = d
k.x = n
k.y = i
d.x = i
f.x = k
n.w = d
a.x = i
i.r = f
i.x = c
i.y = k
h.x = k
assert a.x.r.x.y.x.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.r: C = None
        self.x: A = None
        self.y: B = None
        self.txt = txt

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

c = A("c")
k = B("k")
d = C("d")
f = C("f")
n = A("n")
a = C("a")
i = B("i")
h = C("h")

c.w = h
k.r = d
k.x = n
k.y = i
d.x = i
f.x = k
n.w = d
a.x = i
i.r = f
i.x = c
i.y = k
h.x = k
assert a.x.r.x.y.x.w.x.txt == "k"