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

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

j = A("j")
e = B("e")
k = A("k")
l = B("l")
h = A("h")
n = B("n")
d = B("d")
a = B("a")

j.w = l
j.p = k
e.u = k
e.v = h
k.w = n
k.p = h
l.u = k
l.v = j
h.w = e
h.p = j
n.u = j
n.v = j
d.u = k
d.v = k
a.u = h
a.v = k
assert n.u.w.u.w.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
e = B("e")
k = A("k")
l = B("l")
h = A("h")
n = B("n")
d = B("d")
a = B("a")

j.w = l
j.p = k
e.u = k
e.v = h
k.w = n
k.p = h
l.u = k
l.v = j
h.w = e
h.p = j
n.u = j
n.v = j
d.u = k
d.v = k
a.u = h
a.v = k
assert n.u.w.u.w.u.w.txt == "l"