#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tes;
  cin >> tes;
  while (tes--) {
    long long int n, m;
    cin >> m >> n;
    vector<pair<long long int, long long int>> arr(n);
    for (long long int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;
    sort(arr.begin(), arr.end());
    vector<long long int> flower(n);
    vector<long long int> cum(n + 1);
    for (long long int i = 0; i < n; i++) flower[i] = arr[i].first;
    cum[n] = 0;
    for (int i = n - 1; i >= 0; i--) cum[i] = cum[i + 1] + flower[i];
    long long int ans, here, left;
    ans = 0;
    m--;
    for (long long int i = 0; i < n; i++) {
      here = 0;
      long long int key = arr[i].second;
      long long int ix =
          (upper_bound(flower.begin(), flower.end(), key) - flower.begin());
      if (ix < n - m) ix = n - m;
      here = here + cum[ix];
      left = m - (n - ix);
      here = here + left * key;
      if (i < ix)
        here = here + arr[i].first;
      else
        here = here + key;
      ans = max(ans, here);
    }
    cout << ans << endl;
  }
}
