Pavers

Count the tilings of a 2 x n board with 1x1 squares, 2x1 rectangles, and L-trominoes, and sum the total number of each paver over all tilings.

Medium6Dynamic programmingCombinatoricsBit manipulationImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

In the land of Quendor, walkways and hallways are always 22mb wide. An mb is a mini bloit, about 1/20001/2000 of a bloit. J. Pierpont Flathead hired the Frobozz Magic Paver Company to lay new walkways at every one of his banks, and he wants to pick the patterns himself. There are so many walkways that Frobozz decided to first write a program that counts every way to cover one walkway completely.

Three kinds of pavers are available.

  • a square paver 11mb on a side
  • a 22mb by 11mb rectangular paver, usable in both orientations
  • a right tromino, the L shaped paver, usable in all four orientations

A paver may not stick out past the walkway and two pavers may not overlap, and every cell of the walkway must be covered by exactly one paver. Two coverings count as different if any paver sits in a different place.

For example, a 2×12 \times 1 walkway has 22 coverings, and adding up the pavers used in both of them gives 22 square pavers of size 1×11 \times 1 and 11 rectangular paver of size 2×12 \times 1.

A 2×22 \times 2 walkway has 1111 coverings, and adding up the pavers used in all eleven gives 1616 square pavers, 88 rectangular pavers and 44 trominoes.

You are given the length nn of a walkway that is 22mb tall and nnmb long. Write a program that reports how many coverings it has and how many pavers of each kind those coverings use in total. Each per kind count is summed over all coverings, not over a single one.

Input

The first line contains the number of data sets PP. (1P100001 \le P \le 10\,000)

Each of the next PP lines holds one data set. A line contains the data set number KK and the walkway length nn, separated by a single space. (1K100001 \le K \le 10\,000, 1n141 \le n \le 14)

The data sets are independent and are all processed the same way. The upper bound on nn is chosen so that all five output values fit in an unsigned 3232 bit integer.

Output

For each data set, print one line with five integers separated by a single space: the data set number KK, the number of coverings of the 2×n2 \times n walkway, the total number of 1×11 \times 1 square pavers used by those coverings, the total number of 2×12 \times 1 rectangular pavers and the total number of trominoes.