#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<pair<long long, long long>> ar(m);       for (int i = 0; i < m; ++i) {         cin >> ar[i].first >> ar[i].second;       }       sort(ar.begin(), ar.end());       vector<long long> psa(m + 1);       for (int i = 1; i < m + 1; ++i) {         psa[i] = psa[i - 1] + ar[i - 1].first;       }       long long ans = 0;       for (int i = 0; i < m; ++i) {         long long a = ar[i].first;         long long b = ar[i].second;         int j = lower_bound(ar.begin(), ar.end(), make_pair(b, LLONG_MAX)) -                 ar.begin();         long long cur = 0;         if (m - j <= n) {           cur += psa[m] - psa[j];           int x = n - (m - j);           cur += a + (x - 1) * b;           if (j <= i) {             cur -= a;             cur += b;           }         } else {           cur += psa[m] - psa[m - n];         }         ans = max(ans, cur);       }       cout << ans <<   n ;     }     return 0;   }   