#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> P, fir;
long long sum_last(long long k) {
  return P.back() - (k >= P.size() ? 0 : P[P.size() - 1 - k]);
}
void solve() {
  long long a, k;
  cin >> k >> a;
  pair<long long, long long> m[a];
  for (int q = 0; q < a; q++) cin >> m[q].first >> m[q].second;
  long long o = 0;
  sort(m, m + a);
  P = vector<long long>(a);
  fir = vector<long long>(a);
  for (int q = 0; q < a; q++) fir[q] = P[q] = m[q].first;
  for (int q = 1; q < a; q++) P[q] += P[q - 1];
  o = sum_last(k);
  for (long long c = 1, q = a - 1; c <= a; c++, q--) {
    long long tyt = m[q].first, eso = k - 1;
    long long ps =
        upper_bound(fir.begin(), fir.end(), m[q].second) - fir.begin();
    long long cnt = a - ps, E = sum_last(cnt);
    if (q >= ps) cnt--, E -= m[q].first;
    if (cnt <= eso)
      tyt += E + m[q].second * (eso - cnt);
    else {
      long long lf = a - eso;
      E = sum_last(eso);
      if (q >= lf) E = sum_last(eso + 1) - m[q].first;
      tyt += E;
    }
    o = max(o, tyt);
  }
  cout << o << "\n";
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  int z;
  cin >> z;
  for (; z--;) {
    solve();
  }
}
