Here is my submission : 207504363
and my thinking:
The answer to each query $$$a_{ij}$$$ is the size of the unique elements in row i and column j plus the absolute value of the difference between the index of $$$a_{ij}$$$ in its column and row
Do let me know what I am missing!
Thank you in advance.