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

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

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

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

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

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

b.q = m
b.u = h
h.r = b
d.r = b
c.r = b
i.r = b
m.q = b
m.u = e
l.r = b
a.r = b
e.r = m
assert i.r.q.u.r.u.r.q.u.txt == "h"