#include <bits/stdc++.h>
using namespace std;
string sort(string s) {
  string result = "";
  int n = s.length();
  char a[n];
  for (int i = 0; i < n; i++) {
    a[i] = s[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    result = result + a[i];
  }
  return result;
}
int main() {
  int n, x, y;
  string p, h;
  cin >> n;
  bool cond;
  for (int i = 0; i < n; i++) {
    cin >> p >> h;
    x = p.length();
    y = h.length();
    if (y < x) {
      cout << "NO" << endl;
      continue;
    }
    cond = true;
    for (int j = 0; j <= y - x; j++) {
      if (sort(h.substr(j, x)) == sort(p)) {
        cout << "YES" << endl;
        cond = false;
        break;
      }
    }
    if (cond) {
      cout << "NO" << endl;
    }
  }
}
