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

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

f = A("f")
j = B("j")
m = B("m")
c = A("c")

f.w = c
j.y = m
m.y = j
c.w = f
assert f.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.y: B = None
        self.txt = txt

f = A("f")
j = B("j")
m = B("m")
c = A("c")

f.w = c
j.y = m
m.y = j
c.w = f
assert f.w.w.w.w.txt == "f"