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

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

a = A("a")
j = B("j")
f = A("f")
m = B("m")
i = A("i")
n = A("n")
k = A("k")
c = A("c")
l = A("l")
h = B("h")

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

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

a = A("a")
j = B("j")
f = A("f")
m = B("m")
i = A("i")
n = A("n")
k = A("k")
c = A("c")
l = A("l")
h = B("h")

a.y = j
j.w = m
j.z = c
f.y = m
m.w = j
m.z = k
i.y = m
n.y = m
k.y = h
c.y = h
l.y = h
h.w = j
h.z = a
assert l.y.w.z.y.z.y.w.z.y.txt == "h"