#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int MAXN = 100000;
const int LINF = 2000000000000000001;

//_ ***************************** START Below *******************************



string a;
string b;



//* Find a in-side b 
//* b == main string

bool consistency(int m, int n){
	
	if(m>n) return false;	
	
	unordered_map<char, int> mp;
	for(int i=0; i<m; i++){
	    mp[a[i]]++;
	}
	int size = mp.size();	
	int s = 0, e = 0;
	while(e<n){
	    if(mp.count(b[e])){
	        mp[b[e]]--;
	        if(mp[b[e]] == 0) size--;
	    }	
	    if(e-s+1 < m){
	        e++;
	    }
	    else{
	        if(size==0) return true;	
	        if(mp.count(b[s])){
	            mp[b[s]]++;
	            if(mp[b[s]] == 1) size++;
	        }
	        s++;
	        e++;
	    }
	}	
	return false;
}









bool practice(int m, int n){
	
	return true;
}




void solve() {

	cin >> a >> b;
	int m = a.size();
	int n = b.size();

	cout << boolalpha << consistency(m, n) << endl;
	
	// cout << boolalpha << consistency(m, n) << " -> " << practice(m, n) << endl;
	
}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}