Game

4.8

4 votes
Easy
Problem

Abhishek is playing a game.The game is played on a rectangular grid consisting of N rows and M columns . Initially all the cells of the grid are uncoloured.

Abhishek's initial score is zero. At each turn , he chooses score cell that is yet not coloured and colors that cell. The score obtained in this step will be number of neighbouring coloured cells of the cell that Abhishek coloured in this step . The game will  end when all the cells are coloured .Finally total score obtained at the end of the game will be sum of score obtained in each turn.

Abhishek wants to know what maximum score he can get? Can you please help him in finding this out?

Note:-Two cells are neighbours of each other if they share a side between them.

** INPUT**

   The input will contain an Integer T denoting the no. of test cases . Each test case contain  dimension of grid M & N

**OUTPUT**

   Total sum

CONSTRAINT

0<T<10

0<M<1000

0<N<1000

Sample Input
2

2 2

3 2
Sample Output
4
7
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?