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

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

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

h = A("h")
c = B("c")
l = C("l")
d = C("d")
n = C("n")
f = A("f")
e = C("e")
i = C("i")
m = B("m")
k = A("k")

h.s = l
c.s = h
c.q = m
l.v = f
d.v = k
n.v = f
f.s = n
e.v = k
i.v = k
m.s = k
m.q = c
k.s = i
assert k.s.v.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
l = C("l")
d = C("d")
n = C("n")
f = A("f")
e = C("e")
i = C("i")
m = B("m")
k = A("k")

h.s = l
c.s = h
c.q = m
l.v = f
d.v = k
n.v = f
f.s = n
e.v = k
i.v = k
m.s = k
m.q = c
k.s = i
assert k.s.v.s.v.txt == "k"