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

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

g = A("g")
i = B("i")
k = A("k")
e = B("e")
f = B("f")

g.s = k
g.w = f
i.w = f
k.s = g
k.w = f
e.w = f
f.w = i
assert f.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.w: B = None
        self.txt = txt

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

g = A("g")
i = B("i")
k = A("k")
e = B("e")
f = B("f")

g.s = k
g.w = f
i.w = f
k.s = g
k.w = f
e.w = f
f.w = i
assert f.w.w.w.w.txt == "f"