#K82982. Group Even and Odd Numbers
Group Even and Odd Numbers
Group Even and Odd Numbers
You are given a list of integers and your task is to separate the list into two groups: one group containing all the even numbers and the other containing all the odd numbers. The relative order of the numbers in the original list must be maintained in each group.
The input consists of multiple test cases. For each test case, the first number indicates how many integers follow, and then that many integers are provided. For each test case, output two lines: the first line should list all even numbers (if any) separated by a single space, and the second line should list all odd numbers (if any) separated by a single space. If a group is empty, simply output an empty line for that group.
Note: If a formula is required, use LaTeX formatting (e.g., $n=\text{number of elements}$). However, for this problem, standard grouping logic is sufficient.
inputFormat
The first line of the input contains an integer $T$ representing the number of test cases. Each test case is described in one line as follows:
- The first integer in the line is $N$, denoting the number of integers in the test case.
- Followed by $N$ space-separated integers.
Example:
2 6 1 2 3 4 5 6 3 10 15 20
outputFormat
For each test case, output exactly two lines:
- The first line contains the even numbers (if any) from the test case, in the order they appeared, separated by a single space.
- The second line contains the odd numbers (if any) from the test case, in the order they appeared, separated by a single space.
If a group has no numbers, output an empty line for that group.
## sample2
6 1 2 3 4 5 6
3 10 15 20
2 4 6
1 3 5
10 20
15
</p>