Harmonious Rectangle
题号:NC216008
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

A vertex-colored rectangle is a rectangle whose four vertices are all painted with colors. For a vertex-colored rectangle, it's harmonious if and only if we can find two adjacent vertices with the same color, while the other two vertices also have the same color with each other.

For example, , and are harmonious, while is not (same number for same color, and different numbers for different colors).

For each point in , where is the set of all integers, Kotori wants to paint it into one of the three colors: red, blue, yellow. She wonders the number of different ways to color them so that there exists at least one harmonious rectangle formed by the points, whose edges are all parallel to the x- or y-axis. That is to say, there exists and such that


or


where is the color of point (x, y).

Two coloring plans are considered different if there exists a point having different colors in the two coloring plans.

输入描述:

There are multiple test cases. The first line of the input contains an integer T () indicating the number of test cases. For each test case:

The first and only line contains three integers n, m().

输出描述:

For each test case output one line containing one integer indicating the number of different ways of coloring modulo .
示例1

输入

复制
3
1 4
2 2
3 3

输出

复制
0
15
16485