class A:
    def __init__(self, txt: str):
        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

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

b.w = e
a.r = l
a.q = e
l.r = a
l.q = b
m.r = a
m.q = e
h.r = d
h.q = e
e.w = b
d.r = h
d.q = e
assert h.r.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        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

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

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