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

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

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

j.y = m
a.x = b
a.w = f
f.x = e
f.w = a
d.x = m
d.w = n
b.x = n
b.w = m
h.y = i
e.x = b
e.w = a
m.x = d
m.w = n
i.x = e
i.w = e
n.x = m
n.w = d
assert j.y.x.w.w.x.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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