World War 2

All submissions for this problem are available.
Read problems statements in English, Mandarin Chinese and Russian as well.
Richard Winters: We're not lost, Private... we're in Normandy.
In WW2, allies have placed their mines on the ground which can be considered as a gird of size N*M. Rows are numbered by integers from 1 to N and columns are numbered by integers from 1 to M. Each cell (i,j) has a mine in it if (i+j) is divisible by 2. All the other cells are empty.
Two cells are neighbors if they share a boundary or a corner. Your aim is to move from the first row to the last row using some special rules that the automatic mine placing system follows. The mines won't blow if the following rules are followed:
 If your current row number is odd, from a 'mined' cell(ie. cell having a mine in it) you can move only to a neighboring 'mined' cells in the next row, and similarly, from a 'not mined'(ie. an empty cell) cell you can only move to a neighboring 'not mined' cell in the next row.
 If your current row number is even, you can move to any neighboring cell in the next row, irrespective of the mining.
You have to find the number of ways to reach row number N starting from row number 1, modulo 10^{9}+7. Two ways are different, if there is at least one different cell on the paths.
Input
First line contains T, the number of testcases. Each testcase consists of N and M in one line.
Output
For each testcase, print the required answer in one line.
Constraints
Example
Input: 2 1 5 2 5 Output: 5 8
Explanation
Example case 1.You can start at any of the 5 cells available.
Example case 2.
8 ways are:
(1,1) to (2,2)
(1,2) to (2,1)
(1,2) to (2,3)
(1,3) to (2,2)
(1,3) to (2,4)
(1,4) to (2,3)
(1,4) to (2,5)
(1,5) to (2,4)
Author:  darkshadows 
Editorial  http://discuss.codechef.com/problems/WW2 
Tags  cook50, darkshadows, exponentiation, medium 
Date Added:  19082014 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, 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, 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. 