import java.awt.Point;
import java.io.*;
import java.util.*;
 
import javax.print.attribute.standard.Compression;
 
 
 
 
  class TestClass {
	  static long mod;
	  static Batman Root;
 static class Batman{
	 
	    int value;
	    Batman[] next = new Batman[26];
	    
	    public Batman(int value){
	    	this.value = value;
	    	}
	    
	    
	 
 }
 
 public static void  Insert(String S,int[] F , int start){
	 
	 
		 
	 
	 Batman temp = Root;
	 for(int i=start;i<S.length();i++){
		 int index = S.charAt(i)-'a';
		 
		 if(temp.next[index]==null){
			 temp.next[index] = new Batman(1);
			 F[1]+=1;
			 
		 }else{
			 temp.next[index].value+=1;
			 int xx = temp.next[index].value;
			 F[xx-1]-=1;
			 F[xx]+=1;
			
			// System.out.println(xx+" "+temp.next[index].value);
		 }
		 temp = temp.next[index];
	 }
	 
 }
 
 
public static void main(String args[] ) throws  java.lang.Exception  {
 
 
 
	InputStream inputStream = System.in;
   InputReader in = new InputReader(inputStream);
 
 // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//  BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
   //Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
  // PrintWriter pw = new PrintWriter(new FileWriter("C:\\Users\\Sompathak\\Desktop\\output.txt"));
    //InputStream inputStream = System.in;
    //InputReader in = new InputReader(inputStream);
 // Scanner in = new Scanner(new InputStreamReader(System.in));
//Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt"));
    //we can we will ??? !!!!!! SOM     RISES
int t = in.nextInt();
mod = 1000000007;
long[][] C =  new long[5001][5001];
 
while(t>0){
	t--;
	Root = new Batman(0);
int n = in.nextInt();
int Q = in.nextInt();
String S = in.next();
int[] F = new int[n+1];
for(int i=0;i<=n;i++)
	for(int j=0;j<=Math.min(i,n);j++){
		if(j==0|| j==i)
		{
			C[i][j]=1;
			continue;
			
		}
		
		C[i][j] = C[i-1][j-1] + C[i-1][j];
		C[i][j]%=mod;
	}
for(int i=0;i<n;i++)
	Insert(S,F,i);
 
 
long[] ans = new long[n+1];
 
 
for(int i=1;i<=n;i++){
	for(int j=i;j<=n;j++){
		ans[i]+= F[j]*C[j][i];
		ans[i]%=mod;
	}
}
 
 
 while(Q>0){
	 Q--;
	int cc = in.nextInt();
	long o =0;
	if(cc<=n) o=ans[cc];
	 System.out.println(o);
 }
}
 
 
 
 
}public static class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
 
    public InputReader(InputStream stream)
    {
        this.stream = stream;
    }
 
    public int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read(buf);
            } catch (IOException e)
            {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
 
    public int nextInt()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
 
    public String readString()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do
        {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public double readDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return res * Math.pow(10, nextInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public boolean isSpaceChar(int c)
    {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
 
    public String next()
    {
        return readString();
    }
 
    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}
 }  