#P1909E. Multiple Lamps
Multiple Lamps
Description
You have lamps, numbered from to . Initially, all the lamps are turned off.
You also have buttons. The -th button toggles all the lamps whose index is a multiple of . When a lamp is toggled, if it was off it turns on, and if it was on it turns off.
You have to press some buttons according to the following rules.
- You have to press at least one button.
- You cannot press the same button multiple times.
- You are given pairs . If you press the button , you also have to press the button (at any moment, not necessarily after pressing the button ). Note that, if you press the button , you don't need to press the button .
You don't want to waste too much electricity. Find a way to press buttons such that at the end at most lamps are on, or print if it is impossible.
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of lamps and the number of pairs, respectively.
Each of the next lines contains two integers , (, ). If you press the button , you also have to press the button . It is guaranteed that the pairs are distinct.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
For each test case:
- If there is no choice of buttons that makes at most lamps on at the end, output a single line containing .
- Otherwise, output two lines. The first line should contain an integer () — the number of pressed buttons. The second line should contain integers () — the indices of the pressed buttons (in any order). The must be distinct, and at the end at most lamps must be turned on.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of lamps and the number of pairs, respectively.
Each of the next lines contains two integers , (, ). If you press the button , you also have to press the button . It is guaranteed that the pairs are distinct.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
Output
For each test case:
- If there is no choice of buttons that makes at most lamps on at the end, output a single line containing .
- Otherwise, output two lines. The first line should contain an integer () — the number of pressed buttons. The second line should contain integers () — the indices of the pressed buttons (in any order). The must be distinct, and at the end at most lamps must be turned on.
Note
In the first test case, you need to turn at most lamps on, which means that no lamp can be turned on. You can show that no choice of at least one button turns lamps on.
In the second test case, you can press buttons , , , .
- Initially, all the lamps are off;
- after pressing button , the lamps whose index is a multiple of (i.e., ) are toggled, so lamp is turned on;
- after pressing button , the lamps whose index is a multiple of (i.e., ) are toggled, so lamps , are turned on;
- after pressing button , the lamps whose index is a multiple of (i.e., , , , , ) are toggled, so lamps , , are turned on;
- after pressing button , the lamps whose index is a multiple of (i.e., , ) are toggled, so lamp is turned on.
This is valid because
- you pressed at least one button;
- you pressed all the buttons at most once;
- you pressed button , which means that you had to also press button : in fact, button has been pressed;
- at the end, only lamp is on.
In the third test case, pressing the buttons , , turns only the lamps , , on.