------
## 最终结论
```python
def totalNQueens(n):
    def backtrack(row, cols, diag1, diag2):
        if row == n:
            return 1  # Found a valid arrangement, increment the solution count
        count = 0
        for col in range(n):
            if col in cols or (row - col) in diag1 or (row + col) in diag2:
                continue
            cols.add(col)
            diag1.add(row - col)
            diag2.add(row + col)
            count += backtrack(row + 1, cols, diag1, diag2)  # Recur to place the next queen
            cols.remove(col)
            diag1.remove(row - col)
            diag2.remove(row + col)
        return count

    return backtrack(0, set(), set(), set())
```