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

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

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

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

h.w = i
a.w = c
a.v = i
d.r = a
k.w = a
k.v = d
c.w = k
c.v = d
n.w = i
i.r = c
assert k.w.v.r.v.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

h.w = i
a.w = c
a.v = i
d.r = a
k.w = a
k.v = d
c.w = k
c.v = d
n.w = i
i.r = c
assert k.w.v.r.v.r.v.r.txt == "c"