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

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

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

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

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

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

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