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

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

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

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

h.s = b
l.u = b
k.r = m
k.q = j
b.s = h
m.s = b
j.s = h
assert m.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

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

h.s = b
l.u = b
k.r = m
k.q = j
b.s = h
m.s = b
j.s = h
assert m.s.s.s.s.s.s.txt == "h"