#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s, p;
    cin >> s >> p;
    map<char, long long> mp;
    long long cc = 0, flag = 0;
    for (long long i = 0; i < s.length(); i++) mp[s[i]]++;
    for (long long i = 0; i < p.length(); i++) {
      map<char, long long> mp1;
      for (long long j = i; j < p.length(); j++) {
        mp1[p[j]]++;
        if (mp == mp1 && j - i + 1 == s.length()) {
          flag = 1;
          break;
        }
      }
      if (flag) {
        cc = 1;
        break;
      }
    }
    if (cc)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
