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

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

a = A("a")
b = B("b")
e = B("e")
j = B("j")
n = B("n")
k = A("k")
g = A("g")
d = A("d")
m = A("m")
i = B("i")

a.w = j
a.o = i
b.x = k
b.p = a
e.x = a
e.p = m
j.x = m
j.p = m
n.x = a
n.p = d
k.w = j
k.o = n
g.w = n
g.o = n
d.w = j
d.o = n
m.w = b
m.o = b
i.x = a
i.p = d
assert j.p.w.x.o.p.o.x.w.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.o: B = None
        self.txt = txt

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

a = A("a")
b = B("b")
e = B("e")
j = B("j")
n = B("n")
k = A("k")
g = A("g")
d = A("d")
m = A("m")
i = B("i")

a.w = j
a.o = i
b.x = k
b.p = a
e.x = a
e.p = m
j.x = m
j.p = m
n.x = a
n.p = d
k.w = j
k.o = n
g.w = n
g.o = n
d.w = j
d.o = n
m.w = b
m.o = b
i.x = a
i.p = d
assert j.p.w.x.o.p.o.x.w.p.w.txt == "b"