#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long pown(long long i, long long n) {
  if (i % n == 0) return n;
  return i % n;
}
int isPrime(int n) {
  if (n <= 1) return 1;
  if (n <= 3) {
    if (n == 2)
      return 2;
    else
      return 3;
  }
  if (n % 2 == 0 || n % 3 == 0) {
    if (n % 2 == 0)
      return 2;
    else
      return 3;
  }
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) {
      if (n % i == 0)
        return i;
      else
        return i + 2;
    }
  return n;
}
long long greatest_power(long long p, long long n) {
  long long u = ceil(log(n) / log(p));
  long long sum = 0;
  long long f = p;
  for (int i = 1; i <= u + 1; i++) {
    sum += (n / f);
    f = f * p;
  }
  return sum;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else if (b == 0) {
    return a;
  } else if (a > b) {
    return gcd(b, a % b);
  } else {
    return gcd(a, b % a);
  }
}
bool findPartiion(vector<int> arr, int n) {
  int sum = 0;
  int i, j;
  for (i = 0; i < n; i++) sum += arr[i];
  if (sum % 2 != 0) return false;
  bool part[sum / 2 + 1][n + 1];
  for (i = 0; i <= n; i++) part[0][i] = true;
  for (i = 1; i <= sum / 2; i++) part[i][0] = false;
  for (i = 1; i <= sum / 2; i++) {
    for (j = 1; j <= n; j++) {
      part[i][j] = part[i][j - 1];
      if (i >= arr[j - 1])
        part[i][j] = part[i][j] || part[i - arr[j - 1]][j - 1];
    }
  }
  return part[sum / 2][n];
}
void solve() {
  string p, h;
  cin >> p >> h;
  long long n = p.size();
  char dp[n];
  for (int i = 0; i < n; i++) {
    dp[i] = p[i];
  }
  sort(dp, dp + n);
  long long m = h.size();
  char ch[n];
  bool b = 0;
  for (int i = 0; i <= m - n; i++) {
    bool w = 0;
    for (int j = 0; j < n; j++) {
      ch[j] = h[i + j];
    }
    sort(ch, ch + n);
    for (int j = 0; j < n; j++) {
      if (ch[j] != dp[j]) {
        w = 1;
        break;
      }
    }
    if (!w) {
      b = 1;
      break;
    }
  }
  if (b) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
