import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new File("DEBRUIJN.IN"));
		int T = in.nextInt();
		for(int t=0;t<T;t++){
			int K = in.nextInt();
			String s=in.next();
			Map<String, HashSet<String>> map = new HashMap<String, HashSet<String>>();
			for(int i=0;i<s.length()-K;i++){
				String a = s.substring(i,i+K);
				if(map.containsKey(a)){
					 map.get(a).add(s.substring(i+1,i+1+K));
				}else{
					HashSet <String> set=new HashSet<String>();
					set.add(s.substring(i+1,i+1+K));
					map.put(a,set);
				}				
				
			}
			int count=0;
			for(String a: map.keySet()){
				if(map.get(a).size()>1){
					count++;
				}
			}
			System.out.println(count);
		}
		
	}
}
