Under construction

Still being built. Things may change

2048

Time limit2sMemory limit1024 MB

Summary
Count the 16-color h by w grids where no two side-adjacent cells share a color, modulo 1,000,000,007, for h up to 6 and w up to 10^18.
Level

Hard8 of 10

Topics
Dynamic programming, Matrix, Combinatorics
Solved
No attempts yet

Problem

The game 2048 is played on a 4×44\times 4 grid with 1×11 \times 1 tiles. Pressing an arrow key moves every tile with the same number in that direction and merges them. After each move, a tile with a power of two from 212^{1} to 2162^{16} appears at a random empty position. The game ends when the grid is full and no tiles can be merged.

Hyun is a skilled hacker but not a strong 2048 player. Hyun wanted to make a 2172^{17} tile in this game. Thinking the 4×44\times 4 grid was too narrow to hold 2172^{17}, Hyun used hacking skills to change the width to ww and the height to hh and played again. Even so, Hyun failed to make a 2172^{17} tile every time.

When Dohoon teased Hyun for not being able to merge two 2162^{16} tiles, Hyun tried to argue that there are too many possible ending positions to deal with. However, the width ww has grown so large that Hyun now finds it hard to count those positions. Compute the number of possible final states of the grid when the game ends, on Hyun's behalf. A final state is one where no two adjacent cells hold the same number and every cell holds one of the 16 possible tiles.

Input

The first line contains the number of queries QQ. (1≤Q≤1 000)(1 \leq Q \leq 1\,000)

From the second line on, each of the QQ lines contains the grid height hih_i and width wiw_i, separated by a space. (1≤hi≤6;1≤wi≤1018)(1 \leq h_i \leq 6; 1 \leq w_i \leq 10^{18})

Output

For each query, print the number of possible final states modulo 1 000 000 0071\,000\,000\,007, one per line in order.

Examples1

  1. Example 1

    Input
    3
    1 3
    2 2
    4 4
    
    Expected output
    3600
    50640
    579307730