Knight on Wide Board

A knight can move in any one of 8 directions (see diagram above on the right). A knight’s tour is a succession of moves made by a knight that traverses every square on an M × N chessboard once and only once. A closed knight’s tour is one in which the knight’s last move in the tour places it a single move away from where it started. See example below (follow the numbers in increasing order to trace the path). In this problem you will count the number of closed knight tours. Input A number of inputs (≤ 1000), each line with N and M (0 < N < 5, 1 ≤ M ≤ 1000000000). Output Output one line per input, the number of closed knight tours modulo 1000000007. Sample Input 12 3 10 Sample Output 0 16