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

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

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

k.w = b
i.r = b
d.w = m
l.r = m
f.w = b
n.w = b
g.w = k
c.r = n
b.w = m
m.w = g
assert n.w.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.r: A = None
        self.txt = txt

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

k.w = b
i.r = b
d.w = m
l.r = m
f.w = b
n.w = b
g.w = k
c.r = n
b.w = m
m.w = g
assert n.w.w.w.w.w.w.w.txt == "g"