#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int j, m, n, c, k, t = 0, l, mn, mx, x = 0, y = 0;
  cin >> t;
  while (t--) {
    long long int f = 0;
    x = 0;
    y = 0;
    map<char, long long int> mp1, mp2;
    string s1, s2;
    cin >> s1 >> s2;
    x = s1.length();
    y = s2.length();
    for (long long int i = 0; i < x; i++) {
      mp1[s1[i]]++;
    }
    for (long long int i = 0; i < x; i++) {
      mp2[s2[i]]++;
    }
    for (long long int i = 0; i <= y; i++) {
      for (j = 0; j < x; j++) {
        if (mp1[s1[j]] != mp2[s1[j]]) {
          break;
        }
        if (j == x - 1) {
          cout << "YES" << endl;
          i = y;
          f = 1;
        }
      }
      mp2[s2[i]]--;
      mp2[s2[x]]++;
      x++;
    }
    if (f == 0) cout << "NO" << endl;
  }
}
