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

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

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

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

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

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

d.o = e
d.q = n
a.o = e
c.o = i
c.q = a
h.o = e
b.o = e
k.o = i
e.o = d
e.q = n
i.o = c
i.q = n
n.o = c
m.o = e
assert d.o.o.q.o.q.o.o.txt == "d"