import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int p = 0; p < T; p++){ int m = sc.nextInt(); int n = sc.nextInt(); String[] s = new String[m];//字符迷阵 for(int i = 0; i < m; ++i) s[i] = sc.next(); String word = sc.next(); int r = 0; for(int i = 0; i < m; ++i){ for(int j = 0; j < n; ++j){ StringBuilder sb1 = new StringBuilder();//横串 StringBuilder sb2 = new StringBuilder();//竖串 StringBuilder sb3 = new StringBuilder();//斜串 for(int k = 0; k < word.length(); ++k){ if(j + k < n) sb1.append(s[i].charAt(j + k)); if(i + k < m) sb2.append(s[i + k].charAt(j)); if(i + k < m && j + k < n) sb3.append(s[i + k].charAt(j + k)); } if(String.valueOf(sb1).equals(word)) r++; if(String.valueOf(sb2).equals(word)) r++; if(String.valueOf(sb3).equals(word)) r++; } } System.out.println(r); } } }