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

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

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

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

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

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

e.w = c
j.p = a
j.x = d
n.p = j
n.x = e
h.w = e
a.p = j
a.x = h
d.w = h
c.w = d
f.w = d
i.p = j
i.x = e
assert n.x.w.w.w.txt == "h"