- // Name:- Kunal Sheth 
-   
- //just a half-hearted try...lets hope for the best!!! 
-   
- //header files 
-   
- #include<iostream> 
- #include<cstdio> 
- #include<algorithm> 
- #include<vector> 
- #include<map> 
- #include<cmath> 
- #include<cstring> 
- using namespace std; 
-   
- //end of header files 
-   
-   
- //definitions 
-   
- #define MOD 1000000007 
- #define llu long long unsigned 
- #define lld long long 
- #define ld long 
- #define getchar_unlocked getchar 
- #define putchar_unlocked putchar 
- #define eps 0.0000001 
- //end of definitions 
-   
-   
- //fast input 
-   
- int scan_d()    {int ip=getchar_unlocked(),ret=0,flag=1;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;} 
- ld scan_ld()    {int ip=getchar_unlocked(),flag=1;ld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;} 
- lld scan_lld()    {int ip=getchar_unlocked(),flag=1;lld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;} 
- llu scan_llu()    {int ip=getchar_unlocked();llu ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked());for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return ret;} 
-   
- //end of fast input 
-   
- //fast output 
-   
- //no line break 
- void print_d(int n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[10];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<10);} 
- void print_ld(ld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[11];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);} 
- void print_lld(lld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);} 
- void print_llu(llu n)     {int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);} 
-   
- //new line 
- void println_d(int n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);} 
- void println_ld(ld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);} 
- void println_lld(lld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);} 
- void println_llu(llu n)     {int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);} 
-   
- //special char 
- char sp; 
- void printsp_d(int n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);} 
- void printsp_ld(ld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);} 
- void printsp_lld(lld n)     {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);} 
- void printsp_llu(llu n)     {int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);} 
-   
- //end of fast output 
-   
- double dp[2][26]; 
- double arr[26][26]; 
- double probs[3][26]; 
- string s; 
- int ln; 
- int k; 
-   
- //extra functions 
-   
- string get() 
- { 
-     string ret=""; 
-     char temp=getchar_unlocked(); 
-     while(temp<'a'||temp>'z') 
-         temp=getchar_unlocked(); 
-     while(temp>='a'&&temp<='z') 
-     { 
-         ret+=temp; 
-         temp=getchar_unlocked(); 
-     } 
-     return ret; 
- } 
-   
- void doit() 
- { 
- 	for(int q=0;q<ln;q++) 
- 	{ 
- 		for(int w=0;w<26;w++) 
- 			dp[0][w]=dp[1][w]=0; 
- 		dp[0][s[q]-'a']=1; 
- 		for(int w=0;w<k;w++) 
- 		{ 
- 			for(int i=0;i<26;i++) 
- 			{ 
- 				for(int j=0;j<26;j++) 
- 				{ 
- 					dp[1][i]+=dp[0][j]*arr[j][i]; 
- 				} 
- 			} 
- 			bool is=1; 
- 			for(int i=0;i<26;i++) 
- 			{ 
- 			    //cout<<dp[1][i]<<" "; 
- 			    if(dp[0][i]-dp[1][i]>eps) 
-                    is=0; 
- 				dp[0][i]=dp[1][i]; 
- 				dp[1][i]=0; 
- 			} 
- 			if(is) 
- 			{ 
- 				cout<<"Iters: "<<w<<endl; 
- 			    //cout<<"hua baba...hua\n"; 
- 			    break; 
- 			} 
- 			//cout<<endl; 
- 		} 
- 		for(int w=0;w<26;w++) 
- 			probs[q][w]=dp[0][w]; 
- 	} 
- 	return; 
- } 
-   
- //end of extra fnctions 
-   
-   
- //main 
-   
- map<string,bool>mp; 
-   
- int main() 
- { 
-     int t=scan_d(); 
-     while(t--) 
-     { 
-     	int n=scan_d(); 
-     	k=scan_d(); 
-     	s=get(); 
-     	ln=s.length(); 
-     	for(int i=0;i<26;i++) 
-     		for(int j=0;j<26;j++) 
-     			cin>>arr[i][j]; 
-     	doit(); 
-     	double ans=0; 
-     	while(n--) 
-     	{ 
-     		string tp=get(); 
-     		int tpln=tp.length(); 
-     		if(!mp[tp]&&tpln==ln) 
-     		{ 
-     		    mp[tp]=1; 
-     			double tans=1; 
-     			for(int i=0;i<ln;i++) 
-     				tans*=probs[i][tp[i]-'a']; 
-     			ans+=tans; 
-     		} 
-     	} 
-     	printf("%7lf\n",ans); 
-     	mp.clear(); 
-     } 
-     return 0; 
- } 
-   
- //end of main 
-