This page is still under construction.

Parts of this page are still being built. What you see may change.

Encrypted password

Interview

Time limit2sMemory limit128 MB

Summary
Decide whether the original password's letters can be rearranged to match a contiguous block inside the encrypted password.
Level

Medium5 of 10

Topics
Sliding window, Hash map, String
Solved
No attempts yet

Problem

Someone built a new encryption algorithm. Assume every password is made of lowercase letters only.

Encryption goes like this.

  1. Swap the letters at two different positions of the password. You may skip this step, or repeat it as many times as you want.
  2. Add zero or more characters in front of the result of step 1.
  3. Add zero or more characters behind the result of step 2.

The result of step 3 is the encrypted password.

Cheongho encrypted every password he used with this algorithm. He did it by hand, so he may have slipped somewhere, and he wants a program that checks whether the encryption came out right.

Given an encrypted password and the original password, decide whether the encrypted password can be the result of encrypting the original password with the algorithm above.

Input

The first line has the number of test cases TT. (1≤T≤1001 \le T \le 100)

Each test case takes two lines. The first line holds the encrypted password and the second line holds the original password.

Both strings are made of lowercase letters only, and each has length at least 11 and at most 100 000100\,000. The encrypted password is never shorter than the original password.

Output

Print one line per test case. Print YES if encrypting the original password with the algorithm can produce the given encrypted password, and NO if it cannot.

Examples1

  1. Example 1

    Input
    3
    abcdef
    ecd
    cde
    ecd
    abcdef
    fcd
    
    Expected output
    YES
    YES
    NO