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

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

k = A("k")
c = B("c")
i = A("i")
m = A("m")
l = B("l")
h = A("h")
b = A("b")
g = B("g")
n = B("n")
a = A("a")

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

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

k = A("k")
c = B("c")
i = A("i")
m = A("m")
l = B("l")
h = A("h")
b = A("b")
g = B("g")
n = B("n")
a = A("a")

k.r = h
k.x = h
c.q = m
c.s = n
i.r = a
i.x = k
m.r = a
m.x = k
l.q = h
l.s = n
h.r = i
h.x = a
b.r = m
b.x = a
g.q = m
g.s = c
n.q = a
n.s = g
a.r = m
a.x = m
assert n.q.r.r.txt == "a"