#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long MAX_N = 2e5 + 7;
vector<long long> g[MAX_N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n, m;
    cin >> n >> m;
    pair<long long, long long> a[m];
    for (long long i = 0; i < m; ++i) {
      cin >> a[i].first >> a[i].second;
    }
    sort(a, a + m);
    long long pref[m + 1];
    pref[0] = 0;
    for (long long i = 1; i < m + 1; ++i) {
      pref[i] = pref[i - 1] + a[i - 1].first;
    }
    long long ans = 0;
    for (long long i = 0; i < m; ++i) {
      long long val = a[i].second;
      long long l = -1;
      long long r = m;
      while (l + 1 < r) {
        long long mid = (l + r) / 2;
        if (a[mid].first <= val)
          l = mid;
        else
          r = mid;
      }
      long long need = n;
      long long sum = 0;
      if (a[i].first > val) {
        if (m - r <= need) {
          sum += pref[m] - pref[r];
          need -= m - r;
          sum += val * need;
        } else {
          r = m - need;
          if (r > i) {
            r++;
            sum += pref[m] - pref[r] + a[i].first;
          } else {
            sum += pref[m] - pref[r];
          }
        }
      } else {
        sum += a[i].first;
        need--;
        if (m - r <= need) {
          sum += pref[m] - pref[r];
          need -= m - r;
          sum += need * val;
        } else {
          r = m - need;
          sum += pref[m] - pref[r];
        }
      }
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
}
