#pragma comment(linker, "/STACK: 16777216")

#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back


using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl


using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}


#ifdef _getchar_nolock
#else
#define _getchar_nolock getchar_unlocked
#endif

template <typename T>
void freadT(T &x) {
    x = 0;
    char ch = _getchar_nolock();
    ll sign = 1;

    while (!isdigit(ch)) {
        if (ch == '-')
            sign *= -1;
        ch = _getchar_nolock();
    }

    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = _getchar_nolock();
    }

    x *= sign;
}

int fparse(string s, int start_indx) {
    int x = 0;

    while (isdigit(s[start_indx])) {
        x = x * 10 + s[start_indx] - '0';
        ++start_indx;
    }

    return x;
}

//#define solvsh
//#define multi

#ifdef solvsh
#else


ll mod = 998244353;

ll add(ll a, ll b){
    return (a + b) % mod;
}
ll mult(ll a, ll b) {
    return (a * b) % mod;
}

const int MAXN = 3e5 + 120;
int samex[MAXN];
int samey[MAXN];

void solve() {


    set<pair<int, int>> ms;
    int h, w, m;
    cin >> h >> w >> m;

    for (int i = 0; i < m; ++ i) {
        int hi, wi;
        cin >> hi >> wi;
        ms.insert({hi, wi});

        samex[hi]++;
        samey[wi]++;
    }

    int ind_x_max = 1;
    int ind_y_max = 1;

    vector<int> mxx;
    vector<int> mxy;

    for (int i = 1; i <= h; ++ i) {
        if (samex[i] > samex[ind_x_max])
            ind_x_max = i;
    }

    for (int i = 1; i <= h; ++ i) {
        if (samex[i] == samex[ind_x_max])
            mxx.push_back(i);
    }



    for (int i = 1; i <= w; ++ i) {
        if (samey[i] > samey[ind_y_max])
            ind_y_max = i;
    }

    for (int i = 1; i <= w; ++ i) {
        if (samey[i] == samey[ind_y_max])
            mxy.push_back(i);
    }

    ll cnt = mxx.size();
    cnt *= mxy.size();
    if (cnt > ms.size()) {
        cout << samex[mxx[0]] + samey[mxy[0]];
        return;
    }

    for (auto e : mxx) {
        for (auto e2 : mxy) {
            if (ms.count({e, e2}) == 0)  {

                cout << samex[mxx[0]] + samey[mxy[0]];
                return;
            }
        }
    }


    cout << samex[mxx[0]] + samey[mxy[0]] - 1;

}


#endif

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}


void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        solve();
        i++;
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifndef ONLINE_JUDGE

#else

#endif
#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif
}


Measured memory_bytes: 23856