#include <bits/stdc++.h>
using namespace std;
void invec(vector<long long> &, long long);
long long power(int, int);
int gcnt = 0, gmax = INT_MIN, gmin = INT_MAX;
long long chk(map<char, int> a, map<char, int> b) {
  auto i = a.begin(), j = b.begin();
  for (; i != a.end() && j != b.end(); i++, j++) {
    if (i->second != j->second || i->first != j->first) return 0;
  }
  return 1;
}
void print(map<char, int> a, map<char, int> b) {
  for (auto i : a) cout << i.first << " " << i.second << "\n";
  cout << "\n"
       << "\n";
  ;
  for (auto i : b) cout << i.first << " " << i.second << "\n";
  cout << "\n"
       << "\n";
  ;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string p, h;
    cin >> p >> h;
    if (p.size() > h.size()) {
      cout << "NO"
           << "\n";
      ;
      continue;
    }
    map<char, int> m, hash;
    for (auto k : p) m[k]++;
    for (int k = 0; k < p.size(); k++) hash[h[k]]++;
    long long i = 0, j = p.size() - 1;
    long long f = 1;
    while (j < h.size()) {
      if (chk(m, hash)) {
        cout << "YES"
             << "\n";
        ;
        f = 0;
        break;
      }
      hash[h[i]]--;
      hash[h[j + 1]]++;
      if (hash[h[i]] == 0) hash.erase(h[i]);
      i++;
      j++;
    }
    if (f)
      cout << "NO"
           << "\n";
    ;
  }
}
void invec(vector<long long> &a, long long n) {
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
}
long long power(int a, int n) {
  int ans = 1;
  while (n) {
    if (n & 1) {
      ans *= a;
      n--;
    } else {
      a *= a;
      n /= 2;
    }
  }
  return ans;
}
