#include<iostream>
#include<string>
#include<vector>
using namespace std;
bool up_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows-i][cols]!=haha[i]) return false; } return true;
}
bool down_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows+i][cols]!=haha[i]) return false; } return true;
}
bool left_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows][cols-i]!=haha[i]) return false; } return true;
}
bool right_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows][cols+i]!=haha[i]) return false; } return true;
}
bool up_left_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows-i][cols-i]!=haha[i]) return false; } return true;
}
bool up_right_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows-i][cols+i]!=haha[i]) return false; } return true;
}
bool down_left_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows+i][cols-i]!=haha[i]) return false; } return true;
}
bool down_right_test(vector<string> input,string haha,int rows,int cols)
{ for(int i=0;i<haha.size();i++) { if(input[rows+i][cols+i]!=haha[i]) return false; } return true;
}
int main()
{ vector<string> test; int test_num=0; int rows; int cols; int count=0; vector<int> outall; string test_string; cin>>test_num; for(int i=0;i<test_num;i++) { test.resize(0); cin>>rows>>cols; test.resize(rows); count=0; for(int j=0;j<rows;j++) { cin>>test[j]; } cin>>test_string; for(int x=0;x<rows;x++) for(int y=0;y<cols;y++) { if(test[x][y]==test_string[0]) { if(y>=test_string.size()) { ;//count=count+(int)left_test(test,test_string,x,y); } if(y<=(cols-test_string.size())) { count=count+(int)right_test(test,test_string,x,y); } if(x>=test_string.size()) { ;//count=count+(int)up_test(test,test_string,x,y); } if(x<=(rows-test_string.size())) { count=count+(int)down_test(test,test_string,x,y); } if(y>=test_string.size()&&x>=test_string.size()) { ;//count=count+(int)up_left_test(test,test_string,x,y); } if(y>=test_string.size()&&x<=(rows-test_string.size())) { ;//count=count+(int)down_left_test(test,test_string,x,y); } if(y<=(cols-test_string.size())&&x>=test_string.size()) { ;//count=count+(int)up_right_test(test,test_string,x,y); } if(y<=(cols-test_string.size())&&x<=(rows-test_string.size())) { count=count+(int)down_right_test(test,test_string,x,y); } } } outall.push_back(count); } for(int i=0;i<test_num;i++) { cout<<outall[i]<<endl; } return 0;
}
/*
3
10 10
AAAAAADROW
WORDBBBBBB
OCCCWCCCCC
RFFFFOFFFF
DHHHHHRHHH
ZWZVVVVDID
ZOZVXXDKIR
ZRZVXRXKIO
ZDZVOXXKIW
ZZZWXXXKIK
WORD
3 3
AAA
AAA
AAA
AA
5 8
WORDSWOR
ORDSWORD
RDSWORDS
DSWORDSW
SWORDSWO
SWORD
*/
#网易#