#K80772. Balanced Sequence Generation

    ID: 35605 Type: Default 1000ms 256MiB

Balanced Sequence Generation

Balanced Sequence Generation

You are given a task to generate a balanced sequence of length \(N\) using integers from 1 to \(M\). A sequence is considered "balanced" if the sum of every two adjacent elements is divisible by 3. If \(N=1\), the sequence always exists (simply output [1]). However, if \(N>1\), then a balanced sequence exists only if \(M \ge 3\); otherwise, output "NO SEQUENCE".

For example:

  • For \(N=3\) and \(M=10\), one valid balanced sequence is [1, 2, 1] since \(1+2=3\) and \(2+1=3\), both divisible by 3.
  • For \(N=4\) and \(M=2\), no valid sequence exists, so the output should be NO SEQUENCE.

Your program must read from standard input and print the required answer on standard output.

inputFormat

The first line of the input contains a single integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains two space-separated integers \(N\) and \(M\), representing the length of the sequence and the maximum allowable element, respectively.

outputFormat

For each test case, output a single line. If a balanced sequence exists, print the sequence as a list of space-separated integers. If no such sequence exists, print NO SEQUENCE.

## sample
2
3 10
4 2
1 2 1

NO SEQUENCE

</p>