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

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

e = A("e")
m = B("m")
b = A("b")
f = B("f")
c = B("c")
k = B("k")
a = B("a")
j = A("j")
i = A("i")
h = B("h")

e.w = a
m.u = b
b.w = k
f.u = j
c.u = b
k.u = b
a.u = i
j.w = k
i.w = h
h.u = j
assert m.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

e = A("e")
m = B("m")
b = A("b")
f = B("f")
c = B("c")
k = B("k")
a = B("a")
j = A("j")
i = A("i")
h = B("h")

e.w = a
m.u = b
b.w = k
f.u = j
c.u = b
k.u = b
a.u = i
j.w = k
i.w = h
h.u = j
assert m.u.w.u.txt == "b"