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

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

b = A("b")
m = B("m")
a = A("a")
h = B("h")
d = B("d")
i = B("i")
e = A("e")
f = A("f")
n = B("n")

b.y = m
m.w = a
a.y = i
h.w = f
d.w = b
i.w = a
e.y = i
f.y = n
n.w = f
assert f.y.w.y.w.y.w.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: A = None
        self.txt = txt

b = A("b")
m = B("m")
a = A("a")
h = B("h")
d = B("d")
i = B("i")
e = A("e")
f = A("f")
n = B("n")

b.y = m
m.w = a
a.y = i
h.w = f
d.w = b
i.w = a
e.y = i
f.y = n
n.w = f
assert f.y.w.y.w.y.w.y.txt == "n"