QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#11102. Little Dream

Statistiques

Little Fish has a small dream: he hopes that all people in the world have the ability to distinguish between large and small. The importance of this ability is self-evident — as a contestant, you naturally hope to easily distinguish which problems in a competition are the easiest and which are the hardest; as a human, everyone hopes that all people in the world can distinguish between good and evil, beauty and ugliness.

To this end, Little Fish has started to learn the concepts of minimum and maximum. Today, he found an integer sequence $a_1, a_2, \dots, a_n$. He can perform the following two types of operations any number of times:

  • Choose two adjacent elements $x$ and $y$ in the sequence and replace them with a single element equal to $\min(x, y)$.
  • Choose two adjacent elements $x$ and $y$ in the sequence and replace them with a single element equal to $\max(x, y)$.

After two elements are merged, these two elements are removed from the original sequence, and the new element is inserted at the original position of these two elements.

Little Fish wants to transform the original sequence $a_1, a_2, \dots, a_n$ into another sequence $b_1, b_2, \dots, b_m$. Your task is to determine whether it is possible to transform the sequence into this target sequence through a series of operations.

Input

Each test case contains multiple test cases. The first line contains an integer $T$ ($1 \le T \le 10^5$), representing the number of test cases.

For each test case, the first line contains two integers $n$ and $m$ ($1 \le m \le n \le 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$).

The third line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le n$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

Output

For each test case, if the sequence can be transformed, output a single line containing Yes. Otherwise, output No.

Examples

Input 1

3
2 1
1 2
1
5 4
1 1 1 1 1
1 1 2 1
10 5
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10

Output 1

Yes
No
Yes

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.