#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set1 = tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>;
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define PI 2.0 * acos(0.0)
#define Dpos(n) fixed << setprecision(n)
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 1;
void solve()
{
    ll n, m, i, j, k;
    string s;
    cin >> n >> m;
    vector<string> v1;
    vector<vl> v2(m, vl(26)), v3(m, vl(26));
    for (i = 0; i < n; i++)
    {
        cin >> s;
        v1.push_back(s);
        for (j = 0; j < m; j++)
        {
            v3[j][s[j] - 'a']++;
        }
    }
    ll ans = 0;
    for (i = 0; i < n; i++)
    {
        ll res = 0;
        for (j = 0; j < m; j++)
        {
            char ch = v1[i][j];
            v2[j][ch - 'a']++, v3[j][ch - 'a']--;
        }
        for (j = 0; j < m; j++)
        {
            ll tmp1 = 0, tmp2 = 0;
            for (k = 0; k < 26; k++)
            {
                tmp1 = max(tmp1, v2[j][k]), tmp2 = max(tmp2, v3[j][k]);
            }
            res += (tmp1 + tmp2);
        }
        ans = max(ans, res);
    }
    cout << ans << '\n';
}
int main()
{
    op() int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
    {
        // cout << "Case " << t << ": ";
        solve();
    }
}