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.z: B = None
        self.txt = txt

n = A("n")
k = B("k")
c = B("c")
h = B("h")
j = B("j")
i = A("i")
l = A("l")
g = B("g")
f = B("f")
b = B("b")

n.p = k
n.w = c
k.z = c
c.z = h
h.z = b
j.z = g
i.p = g
i.w = j
l.p = g
l.w = h
g.z = k
f.z = c
b.z = j
assert n.p.z.z.z.z.z.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.z: B = None
        self.txt = txt

n = A("n")
k = B("k")
c = B("c")
h = B("h")
j = B("j")
i = A("i")
l = A("l")
g = B("g")
f = B("f")
b = B("b")

n.p = k
n.w = c
k.z = c
c.z = h
h.z = b
j.z = g
i.p = g
i.w = j
l.p = g
l.w = h
g.z = k
f.z = c
b.z = j
assert n.p.z.z.z.z.z.txt == "g"