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

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

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

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

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

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

m.o = h
g.q = k
g.r = d
j.o = d
k.q = h
k.r = g
i.o = d
c.o = k
l.o = k
a.o = k
d.q = h
d.r = k
h.q = k
h.r = d
assert j.o.r.q.q.q.q.q.r.q.r.txt == "d"