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

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

k = A("k")
e = B("e")
l = B("l")
g = A("g")
a = A("a")
i = B("i")
m = B("m")
h = A("h")
c = A("c")

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

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

k = A("k")
e = B("e")
l = B("l")
g = A("g")
a = A("a")
i = B("i")
m = B("m")
h = A("h")
c = A("c")

k.w = a
k.u = l
e.p = h
l.p = k
g.w = a
g.u = m
a.w = k
a.u = e
i.p = g
m.p = c
h.w = a
h.u = m
c.w = a
c.u = m
assert i.p.w.w.txt == "k"