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

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

k = A("k")
h = B("h")
c = B("c")
n = A("n")
m = B("m")
a = B("a")

k.q = n
h.u = n
h.s = m
c.u = k
c.s = a
n.q = k
m.u = k
m.s = a
a.u = k
a.s = h
assert h.s.u.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

k = A("k")
h = B("h")
c = B("c")
n = A("n")
m = B("m")
a = B("a")

k.q = n
h.u = n
h.s = m
c.u = k
c.s = a
n.q = k
m.u = k
m.s = a
a.u = k
a.s = h
assert h.s.u.q.q.txt == "k"