#include <bits/stdc++.h>
using namespace std;
bool chk(int pp[], int hh[]) {
  for (int i = 0; i < 26; i++)
    if (hh[i] != pp[i]) {
      return 0;
    }
  return 1;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    string p, h;
    cin >> p >> h;
    int pp[26] = {0}, hh[26] = {0};
    for (int i = 0; i < p.length(); i++) pp[p[i] - 'a']++;
    for (int i = 0; i < p.length(); i++) hh[h[i] - 'a']++;
    int t = 0;
    if (chk(pp, hh)) {
      t = 1;
    }
    for (int i = p.length(); i < h.length(); i++) {
      hh[h[i - p.length()] - 'a']--;
      hh[h[i] - 'a']++;
      if (chk(pp, hh)) {
        t = 1;
      }
    }
    if (t == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
