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

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

l = A("l")
m = B("m")
d = A("d")
f = A("f")
e = B("e")
k = A("k")
c = A("c")
n = A("n")

l.w = n
m.w = e
m.u = c
d.w = f
f.w = l
e.w = m
e.u = n
k.w = c
c.w = k
n.w = c
assert k.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

l = A("l")
m = B("m")
d = A("d")
f = A("f")
e = B("e")
k = A("k")
c = A("c")
n = A("n")

l.w = n
m.w = e
m.u = c
d.w = f
f.w = l
e.w = m
e.u = n
k.w = c
c.w = k
n.w = c
assert k.w.w.w.w.txt == "k"