PROGRAMMING:Pop Sequence - Hard Version
Now there is a stack with unlimited capacity. You are supposed to push numbers in a given sequence into the stack one by one, and can pop randomly.
So your task is to check whether a given sequence of numbers is a possible pop sequence. For example, if `2 1 3 6 1 2` is the push sequence, `3 6 1 1 2 2` is a valid pop sequence while `3 6 2 2 1 1` is not.
### Input Specification:
Each input file contains one test case. For each test case, the first line contains an integer $$N$$ (no larger than 20) representing the length of the push sequence, whose $$N$$ elements are given in the second line. Then the third line contains a number $$K$$ (no larger than 10) denoting the number of pop sequences to be checked. Then $$K$$ lines follow, each contains a pop sequence consisting of $$N$$ numbers. All the numbers in a line are separated by a space.
### Output Specification:
For each pop sequence to be checked, print in one line`Yes` if it is valid or `No` if not.
### Sample Input:
```in
six
2 1 3 6 1 2
two
3 6 1 1 2 2
3 6 2 2 1 1
```
### Sample Output:
```out
Yes
No
```
answer:If there is no answer, please comment
So your task is to check whether a given sequence of numbers is a possible pop sequence. For example, if `2 1 3 6 1 2` is the push sequence, `3 6 1 1 2 2` is a valid pop sequence while `3 6 2 2 1 1` is not.
### Input Specification:
Each input file contains one test case. For each test case, the first line contains an integer $$N$$ (no larger than 20) representing the length of the push sequence, whose $$N$$ elements are given in the second line. Then the third line contains a number $$K$$ (no larger than 10) denoting the number of pop sequences to be checked. Then $$K$$ lines follow, each contains a pop sequence consisting of $$N$$ numbers. All the numbers in a line are separated by a space.
### Output Specification:
For each pop sequence to be checked, print in one line`Yes` if it is valid or `No` if not.
### Sample Input:
```in
six
2 1 3 6 1 2
two
3 6 1 1 2 2
3 6 2 2 1 1
```
### Sample Output:
```out
Yes
No
```
answer:If there is no answer, please comment