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

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

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

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

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

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

g.w = k
e.s = a
e.y = g
j.s = i
j.y = d
n.s = g
n.y = a
i.w = n
h.s = d
h.y = i
a.w = n
d.w = j
k.s = i
k.y = a
assert n.y.w.y.w.txt == "n"