

You are given a positive integer N. Return a list of integers of size 2N containing all the integers from 1 to N (both inclusive) twice arranged according to Langford pairing. If no such pairing exists return -1 is the only list element.
Note:There may be more than one Langford pair possible, you need to return anyone permutation.
For example:
For N = 4, one possible Langford pairing will be:-

The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first and only line of each test case or query contains the integer N.
Output format:
The only line of output contains “Valid” if the answer is correct and “Invalid” if it’s not, without quotes.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
0 <= N <= 32
Time Limit: 1 sec
2
4
5
4 1 3 1 2 4 3 2
-1
For the first test case:

For the second test case:
No Langford pairing is possible, hence print -1.
1
15
15 13 14 8 5 12 7 11 4 10 5 9 8 4 7 13 15 14 12 11 10 9 6 3 1 2 1 3 2 6
First off, observe that the question is basically a permutation question, the only twist is that once we fix the first position of one element, the other position of that element is fixed itself.
It can be observed with some examples that for any number N, the permutation following Langford pairing is possible only if either N mod 4 is 0 or 3. Thus, Langford pairing is possible for 3, 4, 7, 8, etc, and not possible for 1, 2, 5, 6, etc. Now to find the sequence,
Algorithm:
bool langfordPairing(result, N):
O(N^N) per test case, where N is the input integer.
In the worst case, we are calling a loop of 2*N size for N numbers.
It should be noted that complexity will actually be less than N^N as, if the answer is possible, we will find it in the halfway itself and if the answer isn’t possible, we will return the function in constant time.
O(N) where N is the size of the array.
In the worst case, extra space is used by the recursion stack.