#include <bits/stdc++.h>   using namespace std;   const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};   const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};   void run() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v(m);     vector<int> id;     for (auto &it : v) {       cin >> it.first >> it.second;       id.push_back(it.first);     }     sort(id.rbegin(), id.rend());     vector<long long> sum(1, 0);     for (auto &it : id) sum.push_back(it + sum.back());     long long mx = sum[min(n, m)];     for (auto &it : v) {       int tmp_n = n;       int j = upper_bound(id.begin(), id.end(), it.second, greater<int>()) -               id.begin();       long long cur = 0;       if (it.first < it.second) {         cur += it.first;         tmp_n--;       }       j = min(j, tmp_n);       cur += sum[j];       tmp_n -= j;       cur += 1LL * tmp_n * it.second;       mx = max(mx, cur);     }     cout << mx <<   n ;   }   int main() {     run();     int T;     cin >> T;     while (T--) {       solve();     }   }   