#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
struct edge {
  int to;
};
using graph = vector<vector<edge>>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    vector<ll> a, b;
    for (int i = 0; i < (m); ++i) {
      ll ai, bi;
      cin >> ai >> bi;
      a.push_back(ai);
      b.push_back(bi);
    }
    vector<ll> asort(begin(a), end(a));
    sort(begin(asort), end(asort), greater<ll>());
    vector<ll> a_s(m + 1, 0);
    for (int i = 1; i < (m + 1); ++i) a_s[i] = a_s[i - 1] + asort[i - 1];
    ll best = 0;
    for (int i = 0; i < (m); ++i) {
      auto it = lower_bound(begin(asort), end(asort), b[i], greater<ll>());
      ll n_gb = it - begin(asort);
      ll ans;
      ll na = min(n, n_gb);
      if (a[i] > b[i]) {
        ll nb = n - na;
        ans = nb * b[i] + a_s[na];
      } else {
        if (na >= n - 1) {
          ans = a_s[n];
        } else {
          ll nb = n - na - 1;
          ans = nb * b[i] + a[i] + a_s[na];
        }
      }
      best = max(best, ans);
    }
    cout << best << "\n";
  }
}
