#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> ip(m);
    for (long long i = 0; i < m; i++) cin >> ip[i].first >> ip[i].second;
    sort(ip.begin(), ip.end(), greater<pair<long long, long long>>());
    long long res = 0;
    long long add = 0;
    for (long long i = 0; i < min(n, m); i++) {
      add += ip[i].first;
      res = max(res, add + (n - i - 1) * ip[i].second);
    }
    long long cnt = 0;
    vector<pair<pair<long long, long long>, long long>> tp;
    for (auto i : ip) {
      tp.push_back({{i.first, 0}, cnt});
      tp.push_back({{i.second, 1}, cnt});
      cnt++;
    }
    sort(tp.begin(), tp.end(),
         greater<pair<pair<long long, long long>, long long>>());
    add = 0;
    long long take = 0;
    long long p = 0;
    vector<bool> hey(m, 0);
    while (p < 2 * m && take < n) {
      if (tp[p].first.second) {
        long long temp = add;
        if (hey[tp[p].second])
          temp += (n - take) * tp[p].first.first;
        else
          temp += (n - take - 1) * tp[p].first.first + ip[tp[p].second].first;
        res = max(res, temp);
      } else {
        take++;
        add += tp[p].first.first;
        hey[tp[p].second] = 1;
      }
      p++;
    }
    cout << res << "\n";
  }
}
