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

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

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

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

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

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

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

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

i.o = l
i.s = h
c.q = k
m.r = b
k.q = c
d.r = n
h.o = l
h.s = l
b.r = m
n.r = m
l.o = i
l.s = i
assert c.q.q.q.txt == "k"