#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[100005];
long long psum[100005];
pair<long long, long long> p[100005];
vector<long long> g[100005];
string s;
char c;
pair<long long, long long> bser(long long b) {
  long long l = 0, r = m - 1;
  long long ans = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (a[mid] > b) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (ans == -1) return make_pair(0, 0);
  if (ans == 0) {
    if (n < m) return make_pair(psum[m - 1] - psum[m - n - 1], n);
    return make_pair(psum[m - 1], m);
  }
  if (n < m - ans) return make_pair(psum[m - 1] - psum[m - n - 1], n);
  return make_pair(psum[m - 1] - psum[ans - 1], m - ans);
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; ++i) {
    long long ai, bi;
    cin >> ai >> bi;
    p[i] = make_pair(bi, ai);
    a[i] = ai;
  }
  sort(p, p + m);
  sort(a, a + m);
  psum[0] = a[0];
  for (long long i = 1; i < m; ++i) psum[i] = psum[i - 1] + a[i];
  long long ans = 0;
  for (long long i = m - 1; i > -1; --i) {
    long long ai = p[i].second;
    long long bi = p[i].first;
    pair<long long, long long> bser_res = bser(bi);
    long long ai_sum = bser_res.first;
    long long num_ais = bser_res.second;
    if (num_ais == n) {
      ans = max(ans, ai_sum);
      continue;
    }
    if (ai > bi) {
      long long num_bis = n - num_ais;
      long long this_ans = ai_sum + num_bis * bi;
      ans = max(ans, this_ans);
    } else {
      long long num_bis = n - num_ais - 1;
      long long this_ans = ai_sum + num_bis * bi + ai;
      ans = max(ans, this_ans);
    }
  }
  cout << ans << endl;
}
void aux() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  aux();
  long long _ = 1;
  cin >> _;
  while (_--) {
    solve();
  }
  return 0;
}
