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

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

b = A("b")
i = B("i")
m = B("m")
l = A("l")
a = B("a")
f = B("f")
k = A("k")
e = A("e")
g = A("g")

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

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

b = A("b")
i = B("i")
m = B("m")
l = A("l")
a = B("a")
f = B("f")
k = A("k")
e = A("e")
g = A("g")

b.q = m
b.r = e
i.u = a
i.w = m
m.u = f
m.w = a
l.q = a
l.r = k
a.u = m
a.w = f
f.u = i
f.w = i
k.q = i
k.r = e
e.q = m
e.r = l
g.q = a
g.r = k
assert g.q.w.w.u.w.u.w.w.u.txt == "m"