#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
pair<int, int> e[MAXN];
int n, m;
long long pre[MAXN];
long long work(int x) {
  int p = upper_bound(e, e + m, make_pair(e[x].second, 0)) - e;
  if (m - p >= n) return pre[m - n];
  int re = n - (m - p);
  if (p <= x) return 1ll * re * e[x].second + pre[p];
  return e[x].first + 1ll * (--re) * e[x].second + pre[p];
}
void run() {
  cin >> n >> m;
  long long ans = 0;
  pre[m] = 0;
  for (int i = 0; i < m; i++) cin >> e[i].first >> e[i].second;
  sort(e, e + m);
  for (int i = m - 1; ~i; i--) pre[i] = pre[i + 1] + e[i].first;
  for (int i = 0; i < m; i++) ans = max(ans, work(i));
  cout << (ans) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  int T;
  for (cin >> T; T--;) run();
  return 0;
}
