#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
ll solve() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> v(m);
  vector<ll> a(m), acca(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
    a[i] = v[i].first;
  }
  sort(a.begin(), a.end());
  for (int i = m - 1; i >= 0; i--) {
    acca[i] = a[i];
    if (i + 1 < m) acca[i] += acca[i + 1];
  }
  ll best = acca[max(0, int(m - n))];
  for (auto item : v) {
    ll A = item.first;
    ll B = item.second;
    int rem = n - 1;
    int idx = std::lower_bound(a.begin(), a.end(), B) - a.begin();
    idx = max(idx, (int)m - rem);
    ll cur = 0;
    if (idx < m) {
      cur = acca[idx];
      rem -= (m - idx);
      if (A < a[idx]) {
        cur += A;
      } else {
        rem++;
      }
      cur += 1ll * rem * B;
    } else {
      cur = A + 1ll * rem * B;
    }
    best = max(best, cur);
  }
  return best;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << "\n";
  }
  return 0;
}
