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

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

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

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

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

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

m.q = b
m.r = d
a.w = h
n.w = l
i.w = l
b.q = l
b.r = h
g.q = m
g.r = d
l.q = h
l.r = g
c.w = b
h.q = b
h.r = g
d.q = g
d.r = l
assert b.r.r.q.q.r.txt == "h"