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

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

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

m.p = a
e.w = j
e.y = n
c.w = i
c.y = n
n.p = a
i.w = j
i.y = n
j.w = c
j.y = a
a.p = n
k.w = c
k.y = n
d.w = e
d.y = m
assert j.y.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

m.p = a
e.w = j
e.y = n
c.w = i
c.y = n
n.p = a
i.w = j
i.y = n
j.w = c
j.y = a
a.p = n
k.w = c
k.y = n
d.w = e
d.y = m
assert j.y.p.p.p.p.p.txt == "n"