#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<pair<long long int, long long int> > v(m);
    vector<long long int> a(m), suff(m + 1);
    for (int i = 0; i < m; i++) {
      cin >> v[i].first >> v[i].second;
      a[i] = v[i].first;
    }
    sort(a.begin(), a.end());
    suff[m - 1] = a[m - 1];
    for (int I = m - 1; I >= 0; I--) suff[I] = suff[I + 1] + a[I];
    long long int ans = 0;
    for (int i = 0; i < m; i++) {
      auto it = upper_bound(a.begin(), a.end(), v[i].second);
      int j = it - a.begin();
      long long int lft = n - m + j, res;
      if (lft <= 0)
        res = suff[m - n];
      else {
        res = suff[j];
        if (v[i].first > v[i].second)
          res += lft * v[i].second;
        else
          res += (lft - 1LL) * v[i].second + v[i].first;
      }
      ans = max(res, ans);
    }
    cout << ans << '\n';
  }
  return 0;
}
