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

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

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

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

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

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

m.r = d
d.q = j
d.r = i
g.r = b
l.r = d
b.q = g
b.r = i
j.r = b
h.r = i
i.q = j
i.r = d
a.r = d
assert a.r.q.r.r.r.txt == "d"