#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string b, c;
  for (int iii = 0; iii < t; iii++) {
    bool f1 = false;
    cin >> b >> c;
    int d = 0;
    sort(b.begin(), b.end());
    if (b.size() > c.size()) {
      cout << "NO" << endl;
      goto momo2;
    }
    for (int i = 0; i < c.size() - b.size() + 1; i++) {
      string s1, s2;
      if (f1 == true) {
        cout << "YES" << endl;
        goto momo2;
      }
      for (int j = i; j < i + b.size(); j++) {
        s1 += c[j];
      }
      sort(s1.begin(), s1.end());
      if (s1 == b) {
        cout << "YES" << endl;
        goto momo2;
      }
    momo0:;
    }
    cout << "NO" << endl;
  momo2:;
  }
  return 0;
}
