This page is still under construction.

Parts of this page are still being built. What you see may change.

Geometric Patterns

Time limit1sMemory limit128 MB

Summary
For each given n, print the numbers of spanning trees of the 2 by n rectangular grid and the 2 by n circular grid modulo 10007.
Level

Medium7 of 10

Topics
Combinatorics, Dynamic programming, Math
Solved
No attempts yet

Problem

People have decorated objects and buildings since prehistoric times. The most important element in that decoration is the geometric pattern, and geometric patterns are easy to spot in everyday life.

Suhwan, an expert in computational geometry, found that geometric patterns are built with great precision on grids and on their subgrids. He recently started a research project that generates geometric patterns automatically.

The grids Suhwan cares about are the rectangular grid and the circular grid. An m×nm \times n rectangular grid is a graph whose vertices and edges form a rectangular lattice in the plane. Each row holds nn vertices and each column holds mm vertices. Its vertex set is {vji:0≤i≤m−1, 0≤j≤n−1}\{v^i_j : 0 \le i \le m-1,\ 0 \le j \le n-1\} and its edge set is {(vji,vqp):∣i−p∣+∣j−q∣=1}\{(v^i_j, v^p_q) : |i-p| + |j-q| = 1\}. An m×nm \times n circular grid is the m×nm \times n rectangular grid with extra edges that wrap it around: for every 0≤i≤m−10 \le i \le m-1, the edge (vn−1i,v0i)(v^i_{n-1}, v^i_0) is added.

Many geometric patterns form a spanning tree of the grid. A spanning tree is a subgraph that contains every vertex and some of the edges, has no cycle, and is connected. Suhwan wants to count the distinct spanning trees of a 2×n2 \times n grid. Every vertex is distinguishable, so two spanning trees that coincide under a rotation or a reflection still count separately when their edge sets differ.

Given nn, write a program that counts the spanning trees of the 2×n2 \times n rectangular grid and the spanning trees of the 2×n2 \times n circular grid.

Input

The first line contains the number of test cases TT. Each of the following TT lines contains one integer nn. (3≤n≤50 0003 \le n \le 50\,000)

Output

For each test case, print RnR_n modulo 10 00710\,007 and CnC_n modulo 10 00710\,007 on one line, separated by a single space. RnR_n is the number of spanning trees of the 2×n2 \times n rectangular grid, and CnC_n is the number of spanning trees of the 2×n2 \times n circular grid.

Examples1

  1. Example 1

    Input
    3
    3
    4
    10
    
    Expected output
    15 75
    56 384
    1211 9033