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

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

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

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

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

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

e.y = a
c.w = n
a.y = m
j.w = n
k.w = e
m.y = e
n.y = i
h.w = n
i.y = m
g.y = a
assert j.w.y.y.y.y.y.txt == "m"