BUREAU - Bureaucracy

Many centuries later lawyers discovered that there were only two types of laws in the kingdom:
² direct law, that states a new norm;
² canceling law, that cancels one of the previous laws.
The law is considered active if and only if there is no active law that cancels it.
You are to write program that ¯nds out which laws are still active.

Long ago, in a kingdom far, far away the king decided to keep a record of all laws of his kingdom. From that moment whenever a new law was passed, a corresponding record was added to the law archive.

Many centuries later lawyers discovered that there were only two types of laws in the kingdom:

  • direct law, that states a new norm;
  • canceling law, that cancels one of the previous laws.

The law is considered active if and only if there is no active law that cancels it.

You are to write program that finds out which laws are still active.

Input

The first line of the input contains T, the number of test cases. T test cases follow.

The first line of each test case contains an integer number n (1 <= n <= 100000) - the number of passed laws.

The following n lines describe one law each. Each description has one of the following formats:

  • "declare", meaning that a direct law was passed.
  • "cancel i", where i is the number of law being cancelled by this one.

The laws are numbered from one.

Output

For each test case your output must contain a line with the number of active laws. The following line must contain numbers of these laws listed in increasing order.

Example

Input:
1
5
declare
cancel 1
declare
cancel 2
cancel 3

Output:
3
1 4 5

Added by:Fidel Schaposnik
Date:2011-01-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACM ICPC 2009, NEERC, Northern Subregional Contest

hide comments
2015-04-04 08:50:25 :.Mohib.:
Any tricky case plz....my code gives perfect o/p but still wa.... :(
2014-07-07 16:52:19 Nishant Gupta
cin gives tle . Use scanf :D
2014-04-16 16:44:50 GOKU
cin cout ...
giving tle
scanf printf AC
2014-03-12 13:55:09 -_-


Last edit: 2014-08-21 19:16:36
2014-03-10 20:06:36 Rishav Goyal
just print and count => AC nothing new
2013-01-31 00:01:28 Santiago Palacio
STL is perfectly fine... just be careful with that particular function, check reserve for vector.

Last edit: 2013-02-03 03:35:57
2013-01-27 22:32:29 SudShekhar
Use scanf + avoid STL functions like push_back() .. will be easy to do then :D
2013-01-23 16:43:06 saket diwakar
piece of cake.....:)
2012-06-15 07:39:34 Mr. Rook
can any give me ans of this sol as i m not getting problem statement
5
declare
cancel 1
cancel 2
cancel 3
declare
2012-05-10 06:28:46 Ajey Golsangi
Note that the following is possible
4
declare
cancel 1
cancel 1
cancel 3
The ans to the above is
2
2 4

Last edit: 2012-05-10 06:29:54
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.