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

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

b = A("b")
a = B("a")
f = A("f")
l = A("l")
j = B("j")
i = B("i")
h = B("h")
n = A("n")
m = B("m")
d = B("d")

b.o = h
a.w = m
f.o = i
l.o = j
j.w = a
i.w = d
h.w = j
n.o = m
m.w = d
d.w = j
assert m.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

b = A("b")
a = B("a")
f = A("f")
l = A("l")
j = B("j")
i = B("i")
h = B("h")
n = A("n")
m = B("m")
d = B("d")

b.o = h
a.w = m
f.o = i
l.o = j
j.w = a
i.w = d
h.w = j
n.o = m
m.w = d
d.w = j
assert m.w.w.w.w.w.txt == "d"