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

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

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

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

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

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

f.y = c
m.y = c
m.o = e
e.y = c
c.y = m
c.o = e
assert f.y.y.o.txt == "e"