#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string p, h;
    cin >> p >> h;
    int lenp = p.size();
    int lenh = h.size();
    int cnt[30] = {0};
    int now[30] = {0};
    for (int j = 0; j < lenp; j++) {
      cnt[p[j] - 97]++;
    }
    for (int j = 0; j < lenp; j++) {
      now[h[j] - 97]++;
    }
    bool ok = 1;
    for (int j = 0; j < 26; j++) {
      if (now[j] != cnt[j]) ok = 0;
    }
    if (ok) {
      cout << "YES\n";
      continue;
    }
    for (int j = lenp; j < lenh; j++) {
      now[h[j] - 97]++;
      now[h[j - lenp] - 97]--;
      bool ok = 1;
      for (int j = 0; j < 26; j++) {
        if (now[j] != cnt[j]) ok = 0;
      }
      if (ok) {
        cout << "YES\n";
        goto gg;
      }
    }
    cout << "NO\n";
  gg:;
  }
  return 0;
}
