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

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

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

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

n.q = a
f.t = m
a.p = m
a.r = f
k.t = m
h.p = m
h.r = k
d.t = m
l.p = n
l.r = k
m.q = l
assert d.t.q.p.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

n.q = a
f.t = m
a.p = m
a.r = f
k.t = m
h.p = m
h.r = k
d.t = m
l.p = n
l.r = k
m.q = l
assert d.t.q.p.q.p.q.txt == "l"