#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int cases;
  cin >> cases;
  string pwd, hash;
  for (int caseid = (int)(0); caseid < (int)(cases); caseid++) {
    cin >> pwd >> hash;
    bool equal = false;
    int n1 = pwd.length(), n2 = hash.length();
    sort(pwd.begin(), pwd.end());
    for (int i = (int)(0); i < (int)(n2 - n1 + 1); i++) {
      string cs = hash.substr(i, n1);
      sort(cs.begin(), cs.end());
      if (pwd.compare(cs) == 0) {
        equal = true;
        break;
      }
    }
    if (equal)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
