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

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

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

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

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

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

e.u = j
e.w = d
k.w = i
j.w = e
i.u = k
i.w = a
d.u = j
d.w = a
g.u = j
g.w = e
n.u = j
n.w = a
a.u = j
a.w = d
assert k.w.w.w.w.txt == "a"