#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
void __print(long long int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename Th, typename V>
void __print(const pair<Th, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename Th>
void __print(const Th &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void binary_rock() {
  long long int n, m;
  cin >> n >> m;
  long long int i, j, k, l;
  vector<pair<long long int, long long int>> p(m);
  for (i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<long long int> c(m, 0);
  sort(p.begin(), p.end());
  c[0] = p[0].first;
  for (i = 1; i < m; i++) {
    c[i] = c[i - 1];
    c[i] += p[i].first;
  };
  ;
  long long int tot = c[m - 1];
  long long int ans = 0;
  for (i = 0; i < m; i++) {
    long long int curr = 0;
    curr = p[i].first;
    if (n == 1) {
    } else {
      long long int rem = (n - 1);
      pair<long long int, long long int> q;
      q.first = p[i].second;
      q.second = -1;
      auto it = lower_bound(p.begin(), p.end(), q);
      ;
      long long int id = it - p.begin();
      long long int sz = (p.end() - it);
      long long int inc = 0;
      if (sz <= rem) {
        if (id == 0)
          curr += (tot);
        else
          curr += (tot - c[id - 1]);
        if (i >= id) inc = 1;
        curr += (p[i].second * (rem - sz));
      } else {
        long long int index = (m - rem);
        if (index == 0)
          curr += (tot);
        else
          curr += (tot - c[index - 1]);
        if (i >= index) inc = 1;
      }
      if (inc) {
        curr -= p[i].first;
        curr += p[i].second;
      }
    }
    ans = max(ans, curr);
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t t1 = clock();
  long long int t = 1;
  cin >> t;
  while (t--) {
    binary_rock();
  }
  clock_t t2 = clock();
  return 0;
}
