#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int q;
  cin >> q;
  while (q--) {
    string a, b;
    cin >> a >> b;
    int able = 0;
    sort(a.begin(), a.end());
    if (b.size() < a.size()) {
      cout << "NO"
           << "\n";
      continue;
    }
    for (int i = 0; i <= (b.size() - a.size()); ++i) {
      string tmp = b.substr(i, a.size());
      sort(tmp.begin(), tmp.end());
      if (tmp == a) {
        able = 1;
      }
    }
    if (able == 1) {
      cout << "YES"
           << "\n";
    } else {
      cout << "NO"
           << "\n";
    }
  }
  return 0;
}
