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

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

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

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

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

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

f.w = m
f.y = m
m.s = f
m.y = f
c.s = f
c.y = f
k.s = f
k.y = f
assert k.s.y.s.y.txt == "m"