#include <bits/stdc++.h>   template <typename T>   class IntegerIterator {    public:     using value_type = T;     using difference_type = std::ptrdiff_t;     using pointer = T*;     using reference = T;     using iterator_category = std::input_iterator_tag;     explicit IntegerIterator(T value) : value(value) {}     IntegerIterator& operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator& operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) const { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {     using IteratorType = std::reverse_iterator<IntegerIterator<T>>;       public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IteratorType begin() const {       return IteratorType(IntegerIterator<T>(begin_));     }     IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     return ReversedIntegerRange<T>(from + 1, to);   }   namespace impl {   using Random = std::mt19937;   }   inline impl::Random& randomEngine() {     static std::random_device device;     static impl::Random engine(device());     return engine;   }   inline int randomInteger() {     std::uniform_int_distribution<int> d;     return d(randomEngine());   }   inline int randomInteger(int to) {     ;     std::uniform_int_distribution<int> d(0, to - 1);     return d(randomEngine());   }   inline int randomInteger(int from, int to) {     return from + randomInteger(to - from);   }   using int64 = int64_t;   using std::endl;   using std::make_pair;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::unique;   using std::vector;   class AShuffleHashing {    public:     static void solveSlow(std::stringstream& in, std::ostream& out) {}     static constexpr int kStressIterations = 0;     static void generateTest(std::ostringstream& in, std::ostringstream& ___) {       auto _____ = std::stringstream(in.str());       solveSlow(_____, ___);     }     static void solve(std::istream& in, std::ostream& out) {       auto solve = [](string p, string h) -> bool {         if (h.size() < p.size()) return false;         sort(p.begin(), p.end());         for (int start : range(h.size() - p.size() + 1)) {           string h_s =   ;           for (int i : range<int>(start, start + p.size())) {             assert(i >= 0 && i < h.size());             h_s.push_back(h[i]);           }           sort(h_s.begin(), h_s.end());           if (p == h_s) return true;         }         return false;       };       int tests;       in >> tests;       for (int test : range(tests)) {         string p, h;         in >> p >> h;         out << (solve(p, h) ?  YES  :  NO ) << endl;       }     }   };   int main() {     std::ios_base::sync_with_stdio(false);     AShuffleHashing solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(nullptr);     solver.solve(in, out);     return 0;   }   