Place queens row by row using backtracking. Each queen goes in a different row, so place exactly one queen per row.
For each row, try each column. Check if the position is safe (no queen attacks it). If safe, place the queen and recurse to the next row. If you reach row , you found a solution.
Track attacked columns and diagonals. Columns: a set. Diagonals: two sets for row - col and row + col.