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

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

n = A("n")
j = B("j")
g = B("g")
d = B("d")
f = A("f")
k = A("k")
a = A("a")
i = B("i")

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

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

n = A("n")
j = B("j")
g = B("g")
d = B("d")
f = A("f")
k = A("k")
a = A("a")
i = B("i")

n.p = d
n.x = k
j.w = i
j.s = f
g.w = d
g.s = a
d.w = g
d.s = n
f.p = d
f.x = k
k.p = d
k.x = n
a.p = j
a.x = k
i.w = j
i.s = k
assert k.p.w.w.w.s.x.p.txt == "d"