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

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

m = A("m")
l = B("l")
k = B("k")
f = A("f")
j = A("j")

m.w = k
l.w = j
k.w = f
f.w = l
j.w = k
assert l.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

m = A("m")
l = B("l")
k = B("k")
f = A("f")
j = A("j")

m.w = k
l.w = j
k.w = f
f.w = l
j.w = k
assert l.w.w.w.txt == "f"