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

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

b = A("b")
d = B("d")
n = A("n")
e = A("e")
k = B("k")
m = B("m")
c = B("c")

b.w = n
d.o = m
n.w = b
e.w = n
k.o = c
m.o = k
c.o = d
assert b.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: B = None
        self.txt = txt

b = A("b")
d = B("d")
n = A("n")
e = A("e")
k = B("k")
m = B("m")
c = B("c")

b.w = n
d.o = m
n.w = b
e.w = n
k.o = c
m.o = k
c.o = d
assert b.w.w.w.w.w.w.txt == "b"