import java.io.*;
import java.util.*;
class TestClass {
public static long MOD = 1000000007;
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
Scanner in = new Scanner();
int t = in.nextInt();
long[][] C = new long[5001][5001];
for (int z = 0; z < t; z++) {
int n = in.nextInt();
int q = in.nextInt();
int[][] cur = new int[n][];
int[][] count = new int[n][n];
int[] length = new int[n];
for (int i = 0; i < n; i++) {
cur[i] = Z(s.substring(i).toCharArray());
for (int j = 1; j < cur[i].length; j++) {
if (cur[i][j] > length[j + i]) {
for (int k = i + length[j + i]; k < i + cur[i][j]; k++) {
count[i][k]++;
}
length[j + i] = cur[i][j];
}
}
}
int[] F = new int[n + 1];
for(int i = 0; i < n; i++){
for(int j = i; j < n; j++){
int v = count[i][j] + (length[i] < (j - i + 1) ? 1 : 0);
F[v]++;
}
}
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;
}
}
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;
}
}
for(int i = 0; i < q; i++){
int v = in.nextInt();
if(v <= n){
out.println(ans[v]);
}else{
out.println(0);
}
}
}
out.close();
}
public static int[] Z(char[] s) {
int[] z = new int[s.length];
int n = s.length;
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (i > R) {
L = R = i;
while (R < n && s[R - L] == s[R])
R++;
z[i] = R - L;
R--;
} else {
int k = i - L;
if (z[k] < R - i + 1) {
z[i] = z[k];
} else {
L = i;
while (R < n && s[R - L] == s[R])
R++;
z[i] = R - L;
R--;
}
}
}
return z;
}
public static int[] KMP
(String val
) { int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.
sort(data, i, data.
length); return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
double other = x * x + a * a;
other
= Math.
sqrt(other
); return val + other;
}
public static class Point implements Comparable
<Point
> {
int x, y;
public Point(int start,
int end
) { this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals
(Object obj
) { if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public int compareTo
(Point o
) { return x - o.x;
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, long b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
static class Scanner {
// System.setOut(new PrintStream(new
// BufferedOutputStream(System.out), true));
// br = new BufferedReader(new InputStreamReader(new
// FileInputStream(new File("input.txt"))));
}
while (st == null || !st.hasMoreTokens()) {
try {
}
}
return st.nextToken();
}
public long nextLong() {
return Long.
parseLong(next
()); }
public int nextInt() {
}
public double nextDouble() {
return Double.
parseDouble(next
()); }
st = null;
try {
return br.readLine();
}
}
public boolean endLine() {
try {
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
return st.hasMoreTokens();
}
}
}
}