#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = LONG_LONG_MIN;
    pair<long long, long long> ab[m];
    for (int i = 0; i < m; i++) cin >> ab[i].first >> ab[i].second;
    sort(ab, ab + m);
    long long suf[m];
    suf[m - 1] = ab[m - 1].first;
    for (int i = m - 2; i >= 0; i--) suf[i] = suf[i + 1] + ab[i].first;
    for (int i = m - 1; i >= 0; i--) {
      long long temp = ab[i].first;
      long long b = ab[i].second;
      pair<long long, long long> p = make_pair(b, LONG_LONG_MAX);
      long long ind = upper_bound(ab, ab + m, p) - ab;
      if (m - ind >= n) {
        ans = max(ans, suf[m - n]);
      } else {
        long long temp = 0;
        if (ind < m) {
          temp += suf[ind];
        }
        long long rem = n - (m - ind);
        if (ind > i) {
          rem--;
          temp += ab[i].first;
        }
        temp += rem * ab[i].second;
        ans = max(ans, temp);
      }
    }
    cout << ans << "\n";
  }
}
