#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> ar(m);
    vector<long long> p(m);
    for (int i = 0; i < m; i++) cin >> ar[i].first >> ar[i].second;
    sort(ar.begin(), ar.end(),
         [&](pair<long long, long long> a, pair<long long, long long> b) {
           return a.first > b.first;
         });
    p[0] = ar[0].first;
    long long ans = 0;
    for (int i = 1; i < m; i++) p[i] = p[i - 1] + ar[i].first;
    for (int i = 0; i < m; i++) {
      int l = 0, r = min(n - 1, m - 1);
      while (l < r) {
        int mid = (l + r) / 2;
        if (r - l == 1) mid = r;
        if (ar[mid].first > ar[i].second)
          l = mid;
        else
          r = mid - 1;
      }
      long long cur = 0, left = n;
      if (ar[l].first > ar[i].second) cur += p[l], left -= (l + 1);
      bool kek = false;
      if (l >= i && ar[l].first > ar[i].second) kek = true;
      if (!kek && left > 0) kek = true, left--, cur += ar[i].first;
      ans = max(ans, cur + max(0ll, left) * ar[i].second);
    }
    cout << ans << "\n";
  }
}
