#K94207. Subsequence Checker

    ID: 38590 Type: Default 1000ms 256MiB

Subsequence Checker

Subsequence Checker

You are given two lists A and B. Your task is to determine whether B is a subsequence of A. In other words, check if there exists a sequence of indices \(1 \le i_1 < i_2 < \cdots < i_m \le n\) such that \(A[i_j] = B[j]\) for all \(1 \le j \le m\), where \(n\) is the length of A and \(m\) is the length of B.

Definition: Given two sequences \(A = [a_1, a_2, \ldots, a_n]\) and \(B = [b_1, b_2, \ldots, b_m]\), we say that \(B\) is a subsequence of \(A\) if there exist indices \(1 \le i_1 < i_2 < \cdots < i_m \le n\) such that \(a_{i_j} = b_j\) for each \(j\) from 1 to \(m\).

If B is a subsequence of A, output YES; otherwise, output NO.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains a single integer \(T\) (\(1 \le T \le 100\)) representing the number of test cases.
  • For each test case:
    • The first line contains an integer \(n\) (size of list A).
    • The second line contains \(n\) space-separated integers representing list A.
    • The third line contains an integer \(m\) (size of list B).
    • The fourth line contains \(m\) space-separated integers representing list B.

Note that \(1 \le m \le n\) and the integers can be any valid integer values.

outputFormat

For each test case, print a single line containing YES if list B is a subsequence of list A, or NO otherwise.

The output is written to standard output (stdout).

## sample
1
5
1 2 3 4 5
3
1 3 5
YES