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

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

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

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

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

n.w = m
k.w = m
f.w = g
m.w = b
g.w = m
i.w = g
b.w = e
e.w = n
c.w = e
assert i.w.w.w.txt == "b"