#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;

//* Template1 for Atmost k (i.e. <= k )

int consistency1(int n, int k){

	int s = 0, e = 0;
	int ans = 0;
	unordered_map<int,int> mp;
	
	
	while(e<n){
		//* Calculate state
		mp[a[e]]++;
		
		if(mp.size() <= k){
			//* Valid Wndow => Compute Result && expand 
			ans = max(ans, (e-s+1));
			e++;
		}
		else{
			//* Invalid window => Keep Shrink Window
			while(s<=e && mp.size() > k){
				mp[a[s]]--;
				if(mp[a[s]] == 0) mp.erase(a[s]);
				s++;
			}
			
			//* Valid window => Compute Result && expand 
			ans = max(ans, (e-s+1));
			e++;
		}
	}
	
	return ans;
}







//* Template2 for Atmost k (i.e. <= k )
//* 	(based on Cache Invalidation) 
 
int consistency2(int n, int k){

	
	unordered_map<int,int> mp;
	int s=0, e=0;
	int ans = 0;
	
	while(e<n){
		
		//* Calculate state
		mp[a[e]]++;
 
		//* Invalid window => Shrink 
		while(s<=e && mp.size()>k){
			mp[a[s]]--;
			if(mp[a[s]]==0) mp.erase(a[s]);
			s++;
		}
 
		//* Valid window guranteed => Compute Result
		ans = max(ans, (e-s+1));
		
		e++;
	}
 
	return ans;
 
}























int practice(int n, int k){
	
	
	return 0;
}
 
 
 


void solve() {

	int k;
	cin >> k;
	cin >> a;
	
	int n = a.size();

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