#include <bits/stdc++.h>
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
vector<string> T(N);
vector<vector<int>> freq(M, vector<int>(26, 0));
// Read input and populate frequency table
for (int i = 0; i < N; ++i) {
cin >> T[i];
for (int j = 0; j < M; ++j) {
freq[j][T[i][j] - 'a']++;
}
}
// Construct the best possible S
string bestS = "";
for (int j = 0; j < M; ++j) {
int maxFreq = 0;
char bestChar = 'a';
for (int c = 0; c < 26; ++c) {
if (freq[j][c] > maxFreq) {
maxFreq = freq[j][c];
bestChar = 'a' + c;
}
}
bestS += bestChar;
}
// Calculate maximum possible score
int maxScore = 0;
for (int i = 0; i < N; ++i) {
int currentScore = 0;
for (int j = 0; j < M; ++j) {
if (T[i][j] == bestS[j]) currentScore++;
}
maxScore = max(maxScore, currentScore);
}
cout << maxScore << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Tc;
cin >> Tc;
while (Tc--) {
solve();
}
return 0;
}