#K70837. Can Form String by Deleting and Rearranging

    ID: 33397 Type: Default 1000ms 256MiB

Can Form String by Deleting and Rearranging

Can Form String by Deleting and Rearranging

Given two strings ( S ) and ( P ), determine whether ( P ) can be obtained as a subsequence of ( S ). In other words, check if it is possible to remove some (possibly zero) characters from ( S ) without changing the order of the remaining characters so that the resulting string equals ( P ). For example, if ( S = \texttt{abcde} ) and ( P = \texttt{ace} ), the answer is YES because by deleting ( b ) and ( d ) from ( S ) we obtain ( ace ). Conversely, if ( P = \texttt{aec} ), the answer is NO because the order of characters in ( S ) does not allow forming ( \texttt{aec} ).

inputFormat

The input is given via standard input. The first line contains an integer ( T ) representing the number of test cases. Each test case consists of two lines: the first line contains the string ( S ) and the second line contains the string ( P ).

outputFormat

For each test case, output a single line containing either YES if ( P ) can be formed from ( S ) by deleting some characters while preserving the order, or NO otherwise.## sample

3
abcde
ace
abcde
aec
abcde
acd
YES

NO YES

</p>