#include <bits/stdc++.h>
using namespace std;
int t;
string s, h;
int main() {
  cin >> t;
  while (t--) {
    cin >> s >> h;
    int len = s.length();
    bool ok = 0;
    sort(s.begin(), s.end());
    for (int i = 0; i + len - 1 < h.length(); i++) {
      string tmp = h.substr(i, len);
      sort(tmp.begin(), tmp.end());
      if (tmp == s) {
        ok = 1;
        break;
      }
    }
    if (ok)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
