#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    string p, h;
    cin >> p >> h;
    vector<int> match(26, 0);
    for (char c : p) {
      match[c - 'a']++;
    }
    if (h.size() < p.size()) {
      cout << "NO" << endl;
      continue;
    }
    vector<int> check(26, 0);
    for (int i = 0; i < p.size(); i++) {
      check[h[i] - 'a']++;
    }
    if (check == match) {
      cout << "YES" << endl;
      continue;
    }
    bool y = false;
    for (int i = 0; i < h.size() - p.size(); i++) {
      check[h[i + p.size()] - 'a']++;
      check[h[i] - 'a']--;
      if (check == match) {
        cout << "YES" << endl;
        y = true;
        break;
      }
    }
    if (!y) {
      cout << "NO" << endl;
    }
  }
}
