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

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

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

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

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

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

n.y = g
m.o = l
c.y = g
a.y = n
g.y = c
e.o = l
l.o = e
d.y = g
h.y = n
assert e.o.o.o.o.o.o.o.txt == "l"