#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string p, h;
    cin >> p >> h;
    sort(p.begin(), p.end());
    bool ok = false;
    for (int i = 0; i < h.size(); ++i) {
      string check = h.substr(i, p.size());
      sort(check.begin(), check.end());
      if (p == check) {
        ok = true;
        break;
      }
    }
    if (ok) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
