class A:
    def __init__(self, txt: str):
        self.o: B = 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.r: B = None
        self.q: A = None
        self.u: B = None
        self.txt = txt

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

k.o = h
d.p = f
n.r = h
n.q = l
n.u = a
l.o = h
a.p = f
f.o = a
h.p = e
e.o = d
assert d.p.o.p.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = 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.r: B = None
        self.q: A = None
        self.u: B = None
        self.txt = txt

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

k.o = h
d.p = f
n.r = h
n.q = l
n.u = a
l.o = h
a.p = f
f.o = a
h.p = e
e.o = d
assert d.p.o.p.o.p.o.txt == "a"