#include <bits/stdc++.h>
using namespace std;

bool check (priority_queue<pair<int, char>> &pq, string &s, int d){
	int soViTriConLai = s.length();
	
	while(!pq.empty()){
		pair<int, char> pr = pq.top();
		pq.pop();
		
		if(s.length() % 2 != 0){
			if(pr.first > s.length() / d + 1) return false;
		}
		else{
			if(pr.first > s.length() / d) return false;
		}
		soViTriConLai -= pr.first;
	}
	
	return true;
}

int main(){
	int t; cin >> t;
	while(t--){
		int d; cin >> d;
		string s; cin >> s;
		
		unordered_map<char, int> ump;
		for(char c : s)
			++ump[c];
			
		priority_queue<pair<int, char>> pq;
		for(auto pr : ump)
			pq.push({pr.second, pr.first});
			
		if(check(pq, s, d)) cout << "1\n";
		else cout << "-1\n";
	}
}