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

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

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

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

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

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

m.p = i
m.w = n
n.x = j
e.x = l
h.x = j
l.p = f
l.w = n
j.p = h
j.w = e
a.p = h
a.w = h
f.x = a
k.x = a
i.x = m
assert e.x.w.x.txt == "j"