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.o: B = None
        self.txt = txt

e = A("e")
a = B("a")
c = B("c")
j = A("j")
l = A("l")
g = A("g")
b = A("b")
d = B("d")
i = B("i")
n = A("n")

e.q = l
e.r = j
a.o = i
c.o = i
j.q = b
j.r = n
l.q = j
l.r = e
g.q = n
g.r = b
b.q = n
b.r = j
d.o = c
i.o = c
n.q = j
n.r = b
assert d.o.o.o.o.o.o.o.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.o: B = None
        self.txt = txt

e = A("e")
a = B("a")
c = B("c")
j = A("j")
l = A("l")
g = A("g")
b = A("b")
d = B("d")
i = B("i")
n = A("n")

e.q = l
e.r = j
a.o = i
c.o = i
j.q = b
j.r = n
l.q = j
l.r = e
g.q = n
g.r = b
b.q = n
b.r = j
d.o = c
i.o = c
n.q = j
n.r = b
assert d.o.o.o.o.o.o.o.txt == "c"