

Let,
N = 5
L = 10
1 4 1 [ENQUEUE (4 ,1)]
1 3 1 [ENQUEUE (3 ,1)]
2 1 [DEQUEUE(1)]
2 2 2 [ENQUEUE(2,2)]
2 2 [DEQUEUE(2)]
Answer:- [0, 0, 4, 0, 2]
(The first queue has 4 and 3 so 4 is dequeued out from queue 1 and queue 2 has integer 2 in it, so 2 is dequeued out from queue 2) .
The first line contains a single integer ‘T’ representing the number of test cases. Then each test case follows.
The first line of each test case contains three integers ‘L’, ‘N’, and ‘Q’ denoting the number of queues to be implemented and the number of queries to be performed.
The next ‘Q’ lines of every test case contain 3 integers ‘A’, ‘B’, and ‘C’ denoting the type of operation, the queue number on which the operation is to be achieved, and the number to be enqueued if ‘T’ is 1.
The next ‘Q’ lines of every test case contain 2 integers ‘A’, and ‘B’ denoting the type of operation, and the queue number on which the operation is to be achieved.
For each test case and for each query, print an integer denoting the number dequeued out if ‘A’ is 2 if there exists a number in the queue otherwise print -1. If ‘A’ is 1, if the enqueue operation is successful, print 0, otherwise print -1 if the queue is full.
The output of each test case should be printed in a separate line.
You are not required to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 5
1 <= L <= 10^5
1 <= A <= 2
1 <= B <= N
1 <= C <= 10^9
Time Limit: 1 sec
We can divide the full array into equal sizes of N and perform enqueue operations if the mentioned queue is not full and dequeue the first element if the queue is not empty.
We can store the front and rear element of every queue and every next free index of every index so that we can process the queries in a constant time.