Drum Decorator (Large)

Count fillings of an R by C cylinder grid where each cell with value K has exactly K edge neighbors with value K, up to rotation, modulo 1000000007.

Hard8CombinatoricsGraphMathNo attempts yetTime limit5sMemory limit512 MB

Problem

You are the drummer in the rock band Denise and the Integers. Your drum is a cylinder, and a rectangular grid of cells is wrapped around its side.

Your band is booked to play in Mathland. The Mathlanders are a tough audience. They expect every cell of the drum to hold a positive integer, so zero and negative integers are not allowed. On top of that, each integer KK must border exactly KK other cells that hold the same integer KK. Bordering means sharing an edge, and touching at a single point does not count. A cell holding 1 touches exactly one other cell holding 1, a cell holding 2 touches exactly two other cells holding 2, and so on. Apart from this rule, it does not matter what the other neighbours of a cell hold. The circular top and bottom of the drum are not cells and need no decoration, so a cell in the top row or in the bottom row touches only three other cells, while every other cell touches four.

For example, this is a valid decoration of a cylinder built from a grid with 3 rows and 5 columns.

Imagine that the two hidden columns on the back of the drum continue the three visible ones.

You want to know how many different valid decorations exist. Two decorations are different when no rotation around the axis of the cylinder turns one into the other. The top and the bottom of the drum are told apart, so the 3×53 \times 5 decoration below differs from the one above.

Here too, the two hidden columns on the back continue the three visible ones.

Your drum has RR rows and CC columns. How many different valid decorations exist? The count can be large, so report it modulo 109+710^9 + 7.

Input

The first line holds the number of test cases, TT. Each of the next TT lines holds two integers separated by a space, RR and CC, the number of rows and the number of columns of the drum.

Limits

  • 1T1001 \le T \le 100
  • 2R1002 \le R \le 100
  • 3C1003 \le C \le 100

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the number of valid decorations modulo 109+710^9 + 7.

Note

For R=2R = 2 and C=4C = 4, the only decoration fills every cell with 3.

For R=3R = 3 and C=5C = 5, there are exactly two decorations, and the two pictures in the statement show one each.