check function for queens problem