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

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

l = A("l")
h = B("h")
b = A("b")
d = B("d")
m = A("m")
k = A("k")
e = A("e")
g = A("g")
a = B("a")

l.s = d
l.w = e
h.r = d
h.q = m
b.s = h
b.w = l
d.r = a
d.q = l
m.s = a
m.w = b
k.s = a
k.w = b
e.s = d
e.w = b
g.s = d
g.w = k
a.r = h
a.q = b
assert l.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: A = None
        self.txt = txt

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

l = A("l")
h = B("h")
b = A("b")
d = B("d")
m = A("m")
k = A("k")
e = A("e")
g = A("g")
a = B("a")

l.s = d
l.w = e
h.r = d
h.q = m
b.s = h
b.w = l
d.r = a
d.q = l
m.s = a
m.w = b
k.s = a
k.w = b
e.s = d
e.w = b
g.s = d
g.w = k
a.r = h
a.q = b
assert l.s.r.r.txt == "h"