//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo t;
vector<llo> it[1000001];
//llo dp[1000001];
llo co[30];
llo ma[30];
llo dp[26][26];
llo dp3[26][26];
llo ma2[30][30];
llo dp2[30][26];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;
while(t--){
llo n,q;
cin>>n>>q;
for(llo ii=0;ii<26;ii++){
ma[ii]=0;
for(int j=0;j<26;j++){
ma2[ii][j]=0;
}
}
for(llo i=0;i<n;i++){
string s;
cin>>s;
it[i].clear();
for(llo j=0;j<26;j++){
co[j]=0;
}
for(llo j=0;j<s.size();j++){
it[i].pb(s[j]-'a');
co[it[i].back()]++;
}
for(llo ii=0;ii<26;ii++){
for(int j=0;j<26;j++){
dp3[ii][j]=0;
}
}
for(llo j=0;j<it[i].size();j++){
for(llo k=0;k<26;k++){
for(llo l=k;l<26;l++){
dp[k][l]=dp3[k][l];
if(it[i][j]>=k and it[i][j]<=l){
dp[k][l]=max(dp[k][l],dp3[k][it[i][j]]+1);
}
}
}
for(llo ii=0;ii<26;ii++){
for(int j=0;j<26;j++){
dp3[ii][j]=dp[ii][j];
}
}
}
for(llo k=0;k<26;k++){
for(llo l=k;l<26;l++){
ma2[k][l]=max(ma2[k][l],dp[k][l]);
}
}
for(llo j=0;j<26;j++){
ma[j]=max(ma[j],co[j]);
}
}
llo ans=0;
for(llo i=0;i<26;i++){
for(llo j=0;j<=26;j++){
for(llo k=0;k<26;k++){
dp2[j][k]=0;
}
}
for(llo j=1;j<=26;j++){
for(llo k=0;k<26;k++){
for(llo l=0;l<k;l++){
if(l<i and k>i){
continue;
}
dp2[j][k]=max(dp2[j][k],dp2[j-1][l]+ma2[l][k]);
}
}
}
for(llo j=0;j<=26 and j<=q;j++){
ans=max(ans,dp2[j][25]+(q-j)*ma[i]);
}
}
//cout<<ma2[0][3]<<":"<<ma2[3][4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