One more weird game

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Leha is playing a very interesting game. The game will be played on a rectangular grid consisting of N rows and M columns. Initially all the cells of the grid are uncolored.
Leha's initial score is zero. At each turn, he chooses some cell that is yet not colored, and colors that cell. The score obtained in this step will be number of neighboring colored cells of the cell that Leha colored in this step. Two cells are neighbors of each other if they share a side between them. The game will end when all the cells are colored. Finally, total score obtained at the end of the game will sum of score obtained in each turn.
Leha wants to know what maximum score he can get? Can you please help him in finding this out?
Input
The first line contains a single integer T denoting the number of test cases. T test cases follow.
Each of the following T lines contains two spaceseparated integers N, M denoting the dimensions of the grid.
Output
For each test case, output a single line containing an integer corresponding to the maximal possible score Leha can obtain.
Constraints
 1 ≤ T ≤ 100
 1 ≤ N, M ≤ 1 000
Subtasks
 Subtask #1[30 points]: 1 ≤ N, M ≤ 3
 Subtask #2[70 points]: 1 ≤ N, M ≤ 1 000
Example
Input: 1 2 2 Output: 4
Explanation
Leha can obtain total score 4 in the following way.
 In the first step, he colors down left cell, all the neighboring cells of this cell are uncolored. So, it adds 0 to total score.
 In second step, he can color upper right cell, it also adds total 0 to the score.
 In third step, he can color top left cell. There are two neighboring cell of this cell, both of which are colored. So, this add 2 to the score.
 In the last step, he can choose the remaining down right cell. There are two neighboring cell of this cell, both of which are colored. So, this also add 2 to the score.
Leha can't obtain a score more than 4. Hence 4 is the answer.
Author:  pavel1996 
Tester:  karanaggarwal 
Editorial  http://discuss.codechef.com/problems/OMWG 
Tags  basicgraph, ltime37, pavel1996, simple, trialerror 
Date Added:  11062016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 