#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


//* Template 1 : 

bool consistency1(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;
}





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

//* Template 2 : 

bool consistency2(int m, int n){
	
	if(m>n) return false;	
	
	int k = m;
	
    unordered_map<char, int> mp;
    for(auto& t : a) mp[t]++;
    
    int sz = mp.size(); 
    
    for(int i=0; i<n; i++){
    	
        if(mp.count(b[i])){
            mp[b[i]]--;
            if(mp[b[i]] == 0) sz--;
        }   
        
        //* Maintain window =>  By  removing  i-k - th element from window
        if(i-k>=0){
            if(mp.count(b[i-k]) ){
                mp[b[i-k]]++;
                if(mp[b[i-k]] == 1) sz++;
            }
        }   
        
        //* K sized  window  
        if(i-k+1 >= 0){
        	if(sz == 0) return true;    
        }
    }   
    
    return false;
}













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

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




void solve() {

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

	cout << boolalpha << consistency1(m, n) << " " << consistency2(m, n) << endl;
	
	// cout << boolalpha << consistency1(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;
}