#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
void needForSpeed() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool isPrime(long long a) {
  if (a < 2) return 0;
  for (long long i = 2; i <= sqrt(a); i++)
    if (a % i == 0) return 0;
  return 1;
}
long long binpow(long long base, long long pow, long long mod) {
  if (pow == 0)
    return 1;
  else if (pow % 2)
    return base * binpow(base, pow - 1, mod) % mod;
  else {
    long long p = binpow(base, pow / 2, mod);
    return p * p % mod;
  }
}
int solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> sorts(m);
  for (int i = 0; i < m; ++i) {
    cin >> sorts[i].first >> sorts[i].second;
  }
  long long ans = 0;
  sort(sorts.begin(), sorts.end());
  vector<long long> suf(m);
  suf[m - 1] = sorts.back().first;
  for (int i = m - 2; i >= 0; --i) suf[i] = suf[i + 1] + sorts[i].first;
  if (n == 1)
    return cout << sorts.back().first << '\n', 0;
  else {
    long long ans = 0;
    for (int i = 0; i < m; ++i) {
      int j = lower_bound(sorts.begin(), sorts.end(),
                          make_pair(sorts[i].second + 1, 0LL)) -
              sorts.begin();
      int cnt = m - j;
      if (cnt > n - 1) {
        cnt = n - 1;
        j = m - cnt;
        ans = max(ans, suf[m - n]);
        continue;
      }
      if (cnt == n - 1 && i >= j && j >= 1 &&
          sorts[j - 1].first > sorts[i].second) {
        --j;
        ++cnt;
      }
      if (i < j) {
        ++cnt;
      }
      long long c = (j == m ? 0 : suf[j]) + (i < j ? sorts[i].first : 0) +
                    (n - cnt) * sorts[i].second;
      ans = max(ans, c);
    }
    cout << ans << '\n';
  }
  return 0;
}
int main() {
  needForSpeed();
  int tests = 1;
  cin >> tests;
  while (tests--) {
    solve();
  }
  return 0;
}
