#include <bits/stdc++.h>
using namespace std;
long long int arx[26] = {0};
long long int ary[26] = {0};
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    for (long long int j = 0; j < 26; j++) {
      arx[j] = 0;
      ary[j] = 0;
    }
    string x, y;
    bool finished = false;
    cin >> x;
    cin >> y;
    for (long long int i = 0; i < x.size(); i++) {
      arx[x[i] - 97]++;
    }
    long long int prev_start = 0;
    for (long long int i = 0; i < y.size(); i++) {
      ary[y[i] - 97]++;
      long long int j = 0;
      for (j = 0; j < 26; j++) {
        if (arx[j] != ary[j]) break;
      }
      if (j == 26) {
        finished = true;
        break;
      }
      if (ary[y[i] - 97] > arx[y[i] - 97]) {
        for (long long int j = 0; j < 26; j++) {
          ary[j] = 0;
        }
        prev_start++;
        i = prev_start - 1;
      }
    }
    if (finished)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
