#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3, INF = 1e9;
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    string p, h;
    bool flag = 1;
    cin >> p >> h;
    if (p.size() > h.size()) {
      cout << "NO" << endl;
      continue;
    }
    vector<int> letp(26), leth(26);
    for (int i = 0; i < p.size(); ++i) {
      letp[p[i] - 'a']++;
    }
    for (int i = 0; i <= h.size() - p.size(); ++i) {
      flag = 1;
      for (int j = 0; j < 26; ++j) leth[j] = 0;
      for (int j = i; j < i + p.size(); ++j) {
        leth[h[j] - 'a']++;
      }
      for (int j = 0; j < 26; ++j) {
        if (letp[j] != leth[j]) flag = 0;
      }
      if (flag) {
        cout << "YES" << endl;
        break;
      }
    }
    if (!flag) cout << "NO" << endl;
  }
  return 0;
}
