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

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

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

i.y = g
j.s = m
j.x = n
e.s = i
e.x = d
c.s = m
c.x = m
m.y = a
n.y = l
l.s = d
l.x = i
g.s = m
g.x = m
a.s = n
a.x = i
d.y = c
assert m.y.s.y.s.y.s.y.s.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

i.y = g
j.s = m
j.x = n
e.s = i
e.x = d
c.s = m
c.x = m
m.y = a
n.y = l
l.s = d
l.x = i
g.s = m
g.x = m
a.s = n
a.x = i
d.y = c
assert m.y.s.y.s.y.s.y.s.y.x.txt == "i"