To transport materials from workshop A to workshop B, a conveyor belt is used. Materials are packed in identical containers and placed on the belt sequentially as they are produced in workshop A. Each container has an urgency level for processing in workshop B. To sort the containers by urgency, a buffer is used at the end of the conveyor, just before entering workshop B.
The buffer operates in steps, and at each step, one of the following operations can be performed:
Move the first container from the conveyor directly to workshop B;
Move the first container from the conveyor to storage (storage operates as a stack: each new container is placed on top of the previous one);
Move the top container from storage to workshop B.
Write a program called PIPELINE that, given a sequence of containers, determines whether it is possible to sort them by urgency using this buffer system.
The first line contains the number of tests . Each of the following lines describes a test and contains an integer (1 \leq K \leq 10\,000)—the number of containers in the sequence, followed by real numbers denoting the urgency levels of the containers as they arrive from workshop A (lower numbers correspond to higher urgency).
For each test, output a single line: output 1 if it is possible to sort the containers by urgency using the described buffer, or 0 otherwise.
Example 1