#include <bits/stdc++.h>
using namespace std;
template <class T = long long>
using V = vector<T>;
template <class T = long long>
using VV = V<V<T>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
inline void err(bool b = true) {
  if (b) {
    cout << -1 << '\n';
    exit(0);
  }
}
template <class T>
inline void fin(bool b = true, T e = 0) {
  if (b) {
    cout << e << '\n';
    exit(0);
  }
}
template <class T>
T Roundup_div(T x, T y) {
  return (x + (y - 1)) / y;
}
const long long INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
  T ret = e;
  while (n) {
    if (n & 1) ret *= a;
    a *= a;
    n >>= 1;
  }
  return ret;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  V<> fir(m);
  V<> da(m);
  V<> sec(m);
  for (long long i = (0); i < (m); ++i) cin >> fir[i] >> sec[i];
  da = fir;
  long long res = 0;
  sort((fir).begin(), (fir).end());
  V<> rui(m + 1, 0);
  for (long long i = (1); i < (m + 1); ++i) rui[i] = rui[i - 1] + fir[m - i];
  for (long long i = (0); i < (m); ++i) {
    long long nc = n;
    long long pre = 0;
    if (sec[i] > da[i]) {
      pre += da[i];
      nc--;
    }
    long long itr =
        lower_bound((fir).begin(), (fir).end(), sec[i]) - fir.begin();
    pre += rui[min(nc, m - itr)];
    if (nc - m + itr > 0) pre += (nc - m + itr) * sec[i];
    chmax(res, pre);
  }
  cout << res << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
}
