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

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

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

l.w = n
g.y = m
g.u = d
d.w = k
n.w = l
j.y = c
j.u = n
k.w = n
m.y = j
m.u = d
f.y = m
f.u = k
c.y = g
c.u = k
assert k.w.w.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.y: B = None
        self.u: A = None
        self.txt = txt

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

l.w = n
g.y = m
g.u = d
d.w = k
n.w = l
j.y = c
j.u = n
k.w = n
m.y = j
m.u = d
f.y = m
f.u = k
c.y = g
c.u = k
assert k.w.w.w.w.w.w.txt == "l"