Under construction

Still being built. Things may change

Complete the Sequence!

Time limit1sMemory limit128 MB

Summary
Given a sequence known to fit a minimal-degree polynomial, use finite differences to extrapolate the next several integer values exactly.
Level

Medium5 of 10

Topics
Math, Implementation, Array
Solved
No attempts yet

Problem

You may know the sequence puzzles from magazines: given a sequence such as 1, 2, 3, 4, 5, what is the next number? Sometimes the answer is easy, sometimes it is quite hard. Because such sequence puzzles are popular, we want to add them to the "Free Time" section of a new portal.

Many of these puzzles can be solved by describing the sequence with a polynomial. For example, the sequence 1, 2, 3, 4, 5 can be seen as a trivial polynomial, and the next number is 6. Even a more complex sequence such as 1, 2, 4, 7, 11 can be described by a polynomial; here 12n2−12n+1\frac{1}{2}n^2 - \frac{1}{2}n + 1 works. Note that even when the members of the sequence are integers, the polynomial coefficients may be any real numbers.

A polynomial has the following form:

P(n)=aD⋅nD+aD−1⋅nD−1+⋯+a1⋅n+a0.P(n) = a_D \cdot n^D + a_{D-1} \cdot n^{D-1} + \cdots + a_1 \cdot n + a_0.

If aD≠0a_D \neq 0, the number DD is called the degree of the polynomial. A constant function P(n)=CP(n) = C can be considered a polynomial of degree 00, and the zero function P(n)=0P(n) = 0 is usually defined to have degree −1-1.

Input

The first line contains a single positive integer TT, the number of test cases that follow.

Each test case consists of two lines. The first line contains two integers SS and CC separated by a single space, with 1≤S<1001 \le S < 100, 1≤C<1001 \le C < 100, and S+C≤100S + C \le 100. Here SS is the length of the given sequence, and CC is how many further numbers you must find.

The second line contains SS integers X1,X2,…,XSX_1, X_2, \ldots, X_S separated by spaces. They form the given sequence. The sequence can always be described by a polynomial P(n)P(n) such that Xi=P(i)X_i = P(i) for every ii. Among all such polynomials, let Pmin⁡P_{\min} be the one of lowest possible degree; this is the polynomial used to complete the sequence.

Output

For each test case, print a single line containing CC integers separated by single spaces. These are the values completing the sequence according to the polynomial of lowest possible degree, that is Pmin⁡(S+1),Pmin⁡(S+2),…,Pmin⁡(S+C)P_{\min}(S+1), P_{\min}(S+2), \ldots, P_{\min}(S+C).

It is guaranteed that every result Pmin⁡(S+i)P_{\min}(S+i) is non-negative and fits into a standard integer type.

Examples4

  1. Example 1

    Input
    4
    6 3
    1 2 3 4 5 6
    8 2
    1 2 4 7 11 16 22 29
    10 2
    1 1 1 1 1 1 1 1 1 2
    1 10
    3
    
    Expected output
    7 8 9
    37 46
    11 56
    3 3 3 3 3 3 3 3 3 3
    
  2. Example 2

    Input
    1
    3 3
    5 5 5
    
    Expected output
    5 5 5
    
  3. Example 3

    Input
    1
    2 2
    2 4
    
    Expected output
    6 8
    
  4. Example 4

    Input
    1
    5 3
    1 4 9 16 25
    
    Expected output
    36 49 64