#include <bits/stdc++.h>
using namespace std;
long long arr[1000], arr1[1000];
int main() {
  long long t, i, j, k, f;
  string s1, s2;
  cin >> t;
  for (i = 0; i < t; i++) {
    f = 0;
    for (j = 0; j < 500; j++) {
      arr[j] = 0;
      arr1[j] = 0;
    }
    cin >> s1;
    cin >> s2;
    if (s2.length() < s1.length()) {
      cout << "NO" << endl;
      continue;
    }
    for (j = 0; j < s1.length(); j++) {
      arr[int(s1[j])]++;
    }
    for (j = 0; j < s1.length(); j++) {
      arr1[int(s2[j])]++;
    }
    f = 0;
    for (j = 0; j < 150; j++) {
      if (arr[j] != arr1[j]) {
        f = 1;
      }
    }
    if (f == 0) {
      cout << "YES" << endl;
      continue;
    }
    for (j = s1.length(); j < s2.length(); j++) {
      f = 0;
      arr1[int(s2[j])]++;
      arr1[int(s2[j - s1.length()])]--;
      for (k = 0; k < 150; k++) {
        if (arr[k] != arr1[k]) {
          f = 1;
        }
      }
      if (f == 0) {
        break;
      }
    }
    if (f == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
