#C8381. Reordering to Form Subsequence

    ID: 52357 Type: Default 1000ms 256MiB

Reordering to Form Subsequence

Reordering to Form Subsequence

You are given two strings s and t. Determine whether it is possible to reorder the characters of s to form a new string that contains t as a subsequence.

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. In other words, for each character in t, its occurrence in the reordered string should appear in the same order as in t.

Example:

  • For s = "abcde" and t = "ace", the answer is YES because after reordering s (or even without reordering) ace appears as a subsequence.
  • For s = "xyz" and t = "abc", the answer is NO because s does not contain the required characters.

Note that the reordering can be arbitrary as long as the count of each character in s is not less than that in t.

inputFormat

The input is given via stdin and consists of multiple test cases.

The first line contains a single integer T (the number of test cases).

Each of the next T lines contains two space-separated strings s and t.

Both strings contain only lowercase English letters.

outputFormat

For each test case, output a single line with YES if it is possible to reorder s to obtain a string that contains t as a subsequence. Otherwise, output NO.

The output should be written to stdout.

## sample
3
abcde ace
abacaba aba
xyz abc
YES

YES NO

</p>