The pet shop holds only dogs and cats. It operates on a “first-in, first-out” basis. People must adopt either the oldest of all animals in the shop or they can select whether they would prefer a dog or a cat but they cannot select which specific animal they would like. Each cat or dog that is bought into the shop is represented by a unique identification number.
There are two types of operations:-
1 ‘uID’ ‘type1’ - where 1 represents an animal is being brought into the shop. ‘uID’ represents a unique identification number allotted to the animal. ‘type1’ is 0 if animal is dog or 1 if animal is cat.
2 ‘type2’ - where 2 represents an animal is being adopted. ‘type2’ is 0 if the oldest dog is preferred. ‘type2’ is 1 if the oldest cat is preferred. ‘type2’ is 2 if either of them is preferred.
You have been given ‘n’ operations which you need to perform in the shop. Your task is to return a vector/list that contains the unique identification number of pets that are adopted in the order they are adopted.
Example :Let's say the pet shop's oldest dog’s uID that has not yet been adopted is 4 and that of the oldest cat is 3.
If operation 2 0 is performed then the oldest dog will be adopted i.e uID 4.
If operation 2 1 is performed then the oldest cat will be adopted i.e uID 3.
If operation 2 2 is performed then the animal older among them will be adopted.
The first line contains a single integer ‘T' representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the number of operations.
Next ‘N' lines contain operations that have to be performed on the shop. Each operation is either of type 1 or 2.
Output Format :
For each test case print a vector/list that contains the unique identification number of pets that are adopted in the order they are adopted.
Note :
1. All the operations are valid.
2. You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 1000
1 <= uID <= 10^6
0 <= type1 <= 1
0 <= type2 <= 2
Time Limit: 1sec
2
2
1 4 0
2 2
6
1 2 0
1 1 0
1 3 1
2 1
2 0
2 2
4
3 2 1
Test case1:
Let’s say ith operation takes place at t=i. The status after each operation is as follows.
1 4 0 - A dog is brought into the shop with uID 4.
2 2 - A person comes to the shop and wants to adopt any animal. So, the oldest animal from the shop is given to him i.e dog with uID 4.
Therefore the order in which pets were adopted was 4.
Test case 2:
Let’s say ith operation takes place at t=i. Status after each operation is as follows.
1 2 0 - A dog is brought into the shop with uID 2.
1 1 0 - A dog is brought into the shop with uID 1.
1 3 1 - A cat is brought into the shop with uID 3.
2 1 - A person comes to the shop and wants to adopt a cat. So, the oldest cat from the shop is given to him i.e cat with uID 3.
2 0 - A person comes to the shop and wants to adopt a dog. So, the oldest dog from the shop is given to him i.e dog with uID 2.
2 2 - A person comes to the shop and wants to adopt any animal. So, the oldest animal from the shop is given to him i.e dog with uID 1.
Therefore the order in which pets were adopted was 3,2,1.

2
4
1 1 1
1 3 0
2 1
2 0
8
1 1 0
1 2 1
1 3 0
1 4 1
2 2
2 2
2 1
2 2
1 3
1 2 4 3
Maintain an array/list to check if a pet has been adopted or not.
We can maintain a list of pets in the order they arrive at the shop. The list must contain 3 parameters unique ID of each pet, whether the pet is a dog or cat, and whether it has been adopted or not.
We can declare a list ‘pets’ which contains all the above details. Declare a list ‘ans’ that is initially empty and stores the unique ID in the order in which they are adopted.
We perform each query as follows:-
O(N^2), where ‘N’ denotes the number of operations.
For each operation of type 2, we need to traverse through the list of pets and find the oldest cat, dog, or animal which has not been adopted yet.
O(N), where ‘N’ denotes the number of operations.
As we perform operations of type 2 we also need to maintain whether the pet has been already adopted or not.