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

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

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

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

i.q = m
m.q = d
n.o = a
n.r = d
h.q = d
k.q = h
a.q = m
l.q = h
d.o = i
d.r = n
assert n.o.q.q.o.q.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

i.q = m
m.q = d
n.o = a
n.r = d
h.q = d
k.q = h
a.q = m
l.q = h
d.o = i
d.r = n
assert n.o.q.q.o.q.q.o.txt == "i"