#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 2e5 + 2;
void solve() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  vector<pii> a(m);
  for (int i = (int)(0); i < (int)(m); i++) {
    scanf("%d", &a[i].first);
    scanf("%d", &a[i].second);
  }
  sort(a.begin(), a.end(), [&](pii a, pii b) { return a.second < b.second; });
  ll sum = 0, ans = 0;
  multiset<int> ms;
  for (int i = (int)(0); i < (int)(m); i++) {
    while ((int)ms.size() and
           (*ms.begin() < a[i].second or (int) ms.size() >= n)) {
      sum -= *ms.begin();
      ms.erase(ms.begin());
    }
    sum += a[i].first;
    ll cur = sum;
    ll rem = n - (int)ms.size() - 1;
    cur += rem * a[i].second;
    ans = max(ans, cur);
    ms.insert(a[i].first);
  }
  printf("%lld\n", ans);
}
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
