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

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

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

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

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

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

k.w = c
k.o = m
a.u = j
n.w = j
n.o = k
i.w = a
i.o = m
j.u = a
c.u = j
m.w = a
m.o = n
h.u = a
f.w = c
f.o = m
assert m.o.w.u.txt == "a"