public static void main(String args[]) throws Throwable {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		for (int T=parseInt(in.readLine().trim()),t=0;t<T;t++) {
			if(t>0)
				sb.append("\n");
			in.readLine();
			char[] str=in.readLine().trim().toCharArray();
			int res=-1;
			for(int i=1;i<=str.length&&res==-1;i++)
				if(str.length%i==0) {
					boolean ws=true;
					for(int j=0;j<str.length&&ws;j+=i) 
						ws=is(str, j, i);
					if(ws)
						res=i;
				}
			sb.append(res).append("\n");
		}
		System.out.print(new String(sb));
	}