#C6636. Array Intersection
Array Intersection
Array Intersection
You are given two arrays of integers. Your task is to compute the intersection of the two arrays, i.e. output all elements from the first array that also occur in the second array. The order of elements in the output must follow their first appearance in the first array. Note that if an element appears multiple times in the first array and is present in the second array, all occurrences should be printed.
The input contains multiple test cases. For each test case, print the intersection on one line, with numbers separated by a single space. If there is no common element, print an empty line.
inputFormat
The input starts with a single integer T on the first line, indicating the number of test cases. Each test case consists of two lines:
- The first line contains space-separated integers representing the first array.
- The second line contains space-separated integers representing the second array.
outputFormat
For each test case, print a single line containing the intersection of the two arrays. The numbers must be printed in the order in which they first appear in the first array, separated by a single space. If no common elements exist, print an empty line.
## sample3
1 2 3
2 3 4
1 2 3 4
2 3 4 5 6
1 2 3
4 5 6
2 3
2 3 4
</p>