#include <bits/stdc++.h>
using namespace std;
constexpr int N = 30;
int cnt[N], cnt2[N], sum = 0;
string s, h;
bool the_same(int st) {
  memset(cnt2, 0, sizeof(cnt2));
  for (int i = st, j = 0; j < s.size() && i < h.size(); ++j, ++i) {
    ++cnt2[h[i] - 'a'];
  }
  for (int i = 0; i < N; ++i) {
    if (cnt2[i] != cnt[i]) return 0;
  }
  return 1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    cin >> s >> h;
    for (auto& u : s) {
      ++cnt[u - 'a'];
    }
    bool M = 0;
    for (int i = 0; i < h.size(); ++i) {
      if (the_same(i)) M = 1;
    }
    cout << (M ? "YES" : "NO") << endl;
  }
}
