#include <bits/stdc++.h>
using namespace std;
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
string a, b;
inline void solve() {
  vector<long long> mapa(26);
  for (long long i = 0; i < a.size(); i++) {
    mapa[a[i] - 'a']++;
  }
  for (int i = 0; i < b.size(); i++) {
    vector<long long> mapb(26);
    for (long long j = i; j < b.size(); j++) {
      mapb[b[j] - 'a']++;
      if (mapa == mapb) {
        printf("YES\n");
        return;
      }
    }
  }
  printf("NO\n");
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int test, tc = 0;
  cin >> test;
  while (test--) {
    cin >> a >> b;
    solve();
  }
  return 0;
}
