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

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

n = A("n")
c = B("c")
a = B("a")
m = A("m")
e = A("e")
d = A("d")
l = A("l")
i = A("i")

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

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

n = A("n")
c = B("c")
a = B("a")
m = A("m")
e = A("e")
d = A("d")
l = A("l")
i = A("i")

n.q = e
c.o = d
a.o = d
m.q = d
e.q = i
d.q = l
l.q = n
i.q = e
assert c.o.q.q.q.q.q.q.txt == "i"