#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 74, OO = 0x3f3f3f3f;
class AShuffleHashing {
 public:
  void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    while (n--) {
      string s, h;
      cin >> s >> h;
      if (h.size() < s.size()) {
        cout << "NO\n";
        continue;
      }
      int f[30] = {}, f2[30] = {};
      for (char c : s) f[c - 'a']++;
      bool flag = true;
      for (int i = 0; i < (int)h.size() - (int)s.size() + 1; i++) {
        flag = true;
        memset(f2, 0, sizeof(f2));
        for (int j = i, sz = 0; sz < s.size(); sz++, j++) {
          f2[h[j] - 'a']++;
        }
        for (int j = 0; j < 26; j++) {
          if (f[j] != f2[j]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          break;
        }
      }
      if (flag) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  AShuffleHashing solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
