#include <bits/stdc++.h>
using namespace std;
void calc() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v;
  vector<long long> a;
  for (long long i = 0; i < m; i++) {
    long long ai, bi;
    cin >> ai >> bi;
    v.push_back(make_pair(ai, bi));
    a.push_back(ai);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<long long> acc(m + 2);
  for (long long i = 1; i <= m; i++) {
    acc[i] = acc[i - 1] + a[i - 1];
  }
  long long ans = -1;
  for (long long i = 0; i < m; i++) {
    long long ai = v[i].first;
    long long bi = v[i].second;
    long long lo, hi;
    lo = 0;
    hi = m;
    while (lo + 1 != hi) {
      long long mid = (lo + hi) / 2;
      if (a[mid] > bi)
        lo = mid;
      else
        hi = mid;
    }
    long long curr, rem;
    if (a[lo] > bi) {
      curr = ai;
      rem = n - 1;
      if (rem > 0) {
        long long used = min(lo + 1, rem);
        curr += acc[used];
        if (a[used - 1] <= ai) {
          curr -= ai;
          rem -= used;
          rem++;
          if (used + 1 <= m && a[used] > bi) {
            rem--;
            curr += a[used];
          }
        } else {
          rem -= used;
        }
        if (rem > 0) curr += rem * bi;
      }
    } else {
      curr = ai;
      rem = n - 1;
      if (rem > 0) curr += rem * bi;
    }
    ans = max(ans, curr);
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) calc();
  return 0;
}
