Lucky

0

0 votes
Medium
Problem

This is a story about a girl named Lucky…

She's so lucky, she's a star, but she cry, cry, cries in her lonely heart, thinking "If there's nothing missing in my life, then why do these tears come at night".

She's a hollywood girl and that life is not what she wants, in this problem we'll help Lucky to destruct her fame.

Lucky is stressed with her career, she can get any contract of movie or cd record, but in hollywood if you reject a contract you loose the friend who propose you the job, but Lucky wanna have a lot of friends, because that makes her cooler.

Hollywood works in the following way:

  • If you reject a contract, you loose a point of fame.
  • If you accept a contract, you gain a point of fame.
  • If you accept a contract of friend N, you cannot reject any future contract of the friend N
  • If you reject a contract of friend N, you cannot accept any future contract of the friend N

Given the contracts, maximize the friends that Lucky has at the end of her career, remember Lucky cannot end with a positive fame.

Input

An integer T (1T100), the Lucky lifes in some universes and reincarnations that she has.

For every Lucky life, you will get an integer C (1C105), the contracts that she receive; followed by C integers separated by a space J (1JC), the identifier number of the friend who proposse a job.

Output

For every Lucky life, you will show an integer F, the friends at the end of Lucky's career.

In the next line, you will show L integers separated by a space, the identifier numbers of Lucky's friends in ascendent order.

Note

Zero is non positive

Lucky prefers have friends with lower identifier numbers.

Sample Input
2
4 3 2 2 1
8 2 3 4 2 3 2 1 4
Sample Output
2
1 3
2
1 3
Time Limit: 3.5
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?