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

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

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

n.y = d
b.r = k
b.w = k
j.y = i
m.y = d
c.y = j
d.y = i
g.y = c
k.r = b
k.w = b
l.y = m
i.y = m
assert n.y.y.y.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

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