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

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

a = A("a")
m = B("m")
b = A("b")
d = B("d")
i = A("i")
l = B("l")
k = A("k")
n = A("n")

a.o = d
a.t = m
m.q = a
b.o = d
b.t = l
d.q = b
i.o = l
i.t = l
l.q = b
k.o = l
k.t = l
n.o = m
n.t = m
assert d.q.t.q.t.q.t.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.t: B = None
        self.txt = txt

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

a = A("a")
m = B("m")
b = A("b")
d = B("d")
i = A("i")
l = B("l")
k = A("k")
n = A("n")

a.o = d
a.t = m
m.q = a
b.o = d
b.t = l
d.q = b
i.o = l
i.t = l
l.q = b
k.o = l
k.t = l
n.o = m
n.t = m
assert d.q.t.q.t.q.t.q.o.txt == "d"