Sly Number

Time limit1sMemory limit128 MB

Summary
Determine whether a cyclic-convolution-based inverse (with entries restricted to {0,1,2}) exists for a given array modulo Q, essentially a search over polynomial ring inverses.
Level

Medium6 of 10

Topics
Math, Brute force, Number theory
Solved
No attempts yet

Problem

A sly number is an array AA of NN integers, each taken from the set {0,1,2}\{0, 1, 2\}. For example, A=(1,1,0,2)A = (1, 1, 0, 2) is a sly number with A[0]=1A[0] = 1, A[1]=1A[1] = 1, A[2]=0A[2] = 0, and A[3]=2A[3] = 2.

A sly number is called ONEONE if A[0]=1A[0] = 1 and A[i]=0A[i] = 0 for every i=1,2,…,N−1i = 1, 2, \dots, N-1.

For two sly numbers AA and BB, the Star Multiplication A⋆BA \star B produces an array CC of length NN defined by

C[k]=∑i=0kA[i]⋅B[k−i]  +  ∑i=k+1N−1A[i]⋅B[N+k−i]C[k] = \sum_{i=0}^{k} A[i]\cdot B[k-i] \;+\; \sum_{i=k+1}^{N-1} A[i]\cdot B[N+k-i]

The result CC is again an array of length NN, but it need not be a sly number (its entries may be larger than 22). Results are reduced modulo a positive integer QQ entrywise:

(C mod Q)[i]=C[i] mod Q(C \bmod Q)[i] = C[i] \bmod Q

Given a sly number AA and a modulus QQ, we look for an inverse sly number BB — that is, a sly number BB, whose entries are again from {0,1,2}\{0, 1, 2\} — such that

(A⋆B) mod Q=ONE(A \star B) \bmod Q = ONE

For each given AA and QQ, decide only whether such an inverse sly number BB exists.

Input

The first line contains the number KK of test cases. Each test case consists of two lines. The first line contains two integers separated by a space: QQ (2≤Q≤1002 \le Q \le 100) and NN (5≤N≤505 \le N \le 50). The second line contains the NN integers of the sly number AA, each from the set {0,1,2}\{0, 1, 2\}, separated by spaces.

Output

Print one line for each test case. If an inverse sly number exists, print A solution can be found. Otherwise, print No solution.

Hint

For the case Q=2Q = 2, N=5N = 5, A=(1,0,1,0,1)A = (1, 0, 1, 0, 1), one possible inverse sly number is B=(0,0,1,1,1)B = (0, 0, 1, 1, 1).

Examples2

  1. Example 1

    Input
    2
    2 5
    1 0 1 0 1
    65 8
    1 2 2 2 1 1 2 2
    
    Expected output
    A solution can be found
    No solution
    
  2. Example 2

    Input
    2
    2 5
    1 0 1 0 1
    5 5
    1 0 1 0 1
    
    Expected output
    A solution can be found
    No solution