#include <bits/stdc++.h>
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
ll getrndll(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); }
template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  int n, m;
  cin >> m >> n;
  vector<int> a(n);
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i)
    cin >> p[i].second >> p[i].first, a[i] = p[i].second;
  sort(a.begin(), a.end());
  sort(p.begin(), p.end());
  vector<ll> pref(n + 1);
  for (int i = n - 1; i >= 0; --i) pref[i] = pref[i + 1] + a[i];
  int j = 0;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    while (j < n && a[j] < p[i].first) ++j;
    int inc = p[i].first > p[i].second;
    int x = min(m - inc, n - j);
    ll res = inc * p[i].second + pref[n - x] + 1LL * p[i].first * (m - x - inc);
    strain(ans, res);
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  srand(time(0));
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
