#include <bits/stdc++.h>
using namespace std;
bool isthere(string s1, string s2);
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s2.size() == s1.size()) {
      if (isthere(s1, s2)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
      continue;
    }
    if (s2.size() < s1.size()) {
      cout << "NO" << endl;
      continue;
    }
    bool y = 0;
    for (int i = 0; i <= (s2.size() - s1.size()); i++) {
      string s = s2.substr(i, s1.size());
      if (isthere(s1, s)) {
        cout << "YES" << endl;
        y = 1;
        break;
      }
    }
    if (y == 0) {
      cout << "NO" << endl;
    }
  }
  return 0;
}
bool isthere(string s1, string s2) {
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  if (s1.compare(s2) == 0) {
    return true;
  }
  return false;
}
