#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    string p, h;
    cin >> p >> h;
    long long int first = 0;
    int n1 = p.length();
    int n2 = h.length();
    sort(p.begin(), p.end());
    for (int i = 0; i < n2; ++i) {
      string b = h.substr(i, n1);
      sort(b.begin(), b.end());
      if (b == p) {
        first = 1;
        break;
      }
    }
    if (!first)
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
  return 0;
}
