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

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

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

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

k.s = l
n.w = f
n.q = l
l.s = h
b.s = n
m.s = l
f.s = b
h.w = k
h.q = b
assert f.s.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

k.s = l
n.w = f
n.q = l
l.s = h
b.s = n
m.s = l
f.s = b
h.w = k
h.q = b
assert f.s.s.q.txt == "l"