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

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

i = A("i")
a = B("a")
g = A("g")
f = A("f")
k = A("k")
n = B("n")
d = A("d")
e = A("e")

i.w = g
a.w = n
g.w = k
f.w = i
k.w = i
n.w = a
d.w = i
e.w = d
assert n.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.w: B = None
        self.txt = txt

i = A("i")
a = B("a")
g = A("g")
f = A("f")
k = A("k")
n = B("n")
d = A("d")
e = A("e")

i.w = g
a.w = n
g.w = k
f.w = i
k.w = i
n.w = a
d.w = i
e.w = d
assert n.w.w.w.w.txt == "n"