#P1758C. Almost All Multiples
Almost All Multiples
Description
Given two integers and , a permutation of length is called funny if is a multiple of for all , , and .
Find the lexicographically minimal funny permutation, or report that no such permutation exists.
A permutation of length is an array consisting of each of the integers from to exactly once.
Let and be permutations of length . Then is lexicographically smaller than if in the first position where and differ, . A permutation is lexicographically minimal if it is lexicographically smaller than all other permutations.
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers and (; ).
The sum of across all test cases does not exceed .
For each test case, if the answer exists, output distinct integers () — the lexicographically minimal funny permutation . Otherwise, output .
Input
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers and (; ).
The sum of across all test cases does not exceed .
Output
For each test case, if the answer exists, output distinct integers () — the lexicographically minimal funny permutation . Otherwise, output .
Note
In the first test case, the permutation satisfies all the conditions: , , and:
- is a multiple of .
- is a multiple of .
In the second test case, the permutation satisfies all the conditions: , , and:
- is a multiple of .
- is a multiple of .
- is a multiple of .
We can show that these permutations are lexicographically minimal.
No such permutations exist in the third test case.