Finding number of solutions nqueens 14 by 14 chessboard
Here's my take on it.
Translate columns 1-14 to 0-13 for internal use and translate back on output.
state keeps track of where the queens are.  state[0] is the row of the queen in column 0, etc.  A None indicates the column is empty.
nQueens() searches state for an empty column and then checks each row in that column for a valid move.  If a move is valid, state is updated and nQueens() is called with the new state. After the recursive call is made, revert the change in state. That avoids the need to make a copy of the state.
The code yields the solutions rather than keeping a list.
printboard() is just to help with visualizing what is going on.  Uncomment some of the calls if you're curious...but only do one of the smaller test cases because there is a lot of output.
I think your imvalid() might be off?
Put the driver code in main().
SIZE = 14


def nQueens(state):
    #printboard(state)
    
    # find an empty column (row==None)
    for col, row in enumerate(state):
        if row is None:
            break
         
    # all columns filled. so it is a solution
    else:
        yield state
            
    for row in range(SIZE):
        # check if row taken
        if not valid(state, row, col):
            continue

        # make the move
        #print(f&quot;col[{col+1}] = {row+1}&quot;)
        state[col] = row
        yield from nQueens(state)
        
        # revert the move to continue the search
        state[col] = None
            

def valid(state, row, col):
    # is there a queen in this row
    if row in state: 
        return False

    # is there a queen on a diagonal
    for c,r in enumerate(state):
        if r is None:
            continue
            
        if col-row == c-r or col+row == c+r:
            return False
                
    return True


def printboard(state):
    print('  '+' '.join(str(i%10) for i in range(1, SIZE+1)))
    for r in range(SIZE):
        print((r+1)%10, end=' ')
        for c in range(SIZE):
            if state[c] == r:
                print('Q', end=' ')
            else:
                print('.', end=' ')
        print()

        
def main(data):
    num_cases = int(data.readline())

    for case_num in range(num_cases):
        # initialize state to all Nones.
        # None means the corresponding column is empty
        state = [None]*SIZE

        # fill in the preset queens
        preset = data.readline().split()
        while preset:
            row = int(preset.pop(0)) - 1
            col = int(preset.pop(0)) - 1
            state[col] = row

        #printboard(state)

        # count the number of solutions
        for n,sol in enumerate(nQueens(state)):
            #printboard(sol)
            pass

        print(n+1)
        

Test it like so:
test = &quot;&quot;&quot;
3
1 1 2 9 3 6 4 10
1 9 12 8 8 5 2 7
2 10 10 3
&quot;&quot;&quot;.strip()

main(io.StringIO(test))

Or call it like:
main(sys.stdin)