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

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

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

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

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

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

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