class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.v: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
k = A("k")
l = B("l")
m = A("m")
g = A("g")
e = B("e")

a.z = g
a.v = n
n.w = k
n.p = e
k.z = m
k.v = e
l.w = m
l.p = n
m.z = a
m.v = e
g.z = k
g.v = n
e.w = a
e.p = n
assert n.w.v.w.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.v: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
k = A("k")
l = B("l")
m = A("m")
g = A("g")
e = B("e")

a.z = g
a.v = n
n.w = k
n.p = e
k.z = m
k.v = e
l.w = m
l.p = n
m.z = a
m.v = e
g.z = k
g.v = n
e.w = a
e.p = n
assert n.w.v.w.v.p.txt == "e"