#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tests;
  cin >> tests;
  while (tests--) {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) {
      cout << "NO" << endl;
      continue;
    }
    bool ok = 0;
    vector<int> cnt(300, 0);
    for (char ch : a) ++cnt[ch];
    for (int i = 0; i < (int)a.size(); ++i) --cnt[b[i]];
    if (count(cnt.begin(), cnt.end(), 0) == 300) ok = 1;
    for (int i = 0, j = a.size(); j < b.size(); ++i, ++j) {
      ++cnt[b[i]];
      --cnt[b[j]];
      if (count(cnt.begin(), cnt.end(), 0) == 300) ok = 1;
    }
    cout << (ok ? "YES" : "NO") << endl;
  }
  return 0;
}
