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

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

k = A("k")
g = B("g")
h = B("h")
m = A("m")
e = A("e")
i = B("i")
j = B("j")
d = B("d")
n = A("n")

k.w = m
g.o = e
g.r = n
h.o = m
h.r = n
m.w = k
e.w = k
i.o = m
i.r = k
j.o = n
j.r = e
d.o = m
d.r = m
n.w = e
assert i.r.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.o: A = None
        self.r: A = None
        self.txt = txt

k = A("k")
g = B("g")
h = B("h")
m = A("m")
e = A("e")
i = B("i")
j = B("j")
d = B("d")
n = A("n")

k.w = m
g.o = e
g.r = n
h.o = m
h.r = n
m.w = k
e.w = k
i.o = m
i.r = k
j.o = n
j.r = e
d.o = m
d.r = m
n.w = e
assert i.r.w.w.w.w.w.w.txt == "k"