#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(vector<T>& v) {
  for (T x : v) cout << x << " ";
  cout << "\n";
}
void inp(vector<int>& v, int n) {
  for (int i = 0; i < n; ++i) scanf("%d ", &v[i]);
}
void sol() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, int>> v(m);
  vector<int> sr(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &v[i].first, &v[i].second);
    sr[i] = v[i].first;
  }
  sort(v.begin(), v.end());
  sort(sr.begin(), sr.end());
  unsigned long long res = 0, tmp;
  vector<unsigned long long> suffix(m + 1);
  suffix[m] = 0;
  int ind;
  for (int i = m - 1; i > -1; --i) suffix[i] = suffix[i + 1] + sr[i];
  for (int i = 0; i < m; ++i) {
    tmp = 0;
    ind = upper_bound(sr.begin(), sr.end(), v[i].second) - sr.begin();
    tmp += suffix[max(m - n, ind)];
    if (ind > i && ind > m - n) {
      tmp += sr[i];
      ind--;
    }
    tmp += 1ull * v[i].second * (max(0, n + ind - m));
    res = max(res, tmp);
  }
  printf("%lld\n", res);
  return;
}
int main() {
  int t;
  cin >> t;
  t++;
  for (int i = 1; i < t; ++i) {
    sol();
  }
  return 0;
}
