#include <bits/stdc++.h>
using namespace std;
struct s {
  long long value, type, idx;
};
bool operator<(s a, s b) {
  if (a.value != b.value) return a.value < b.value;
  if (a.type != b.type) return a.type < b.type;
  return a.idx < b.idx;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  cin >> tt;
  for (long long z(0); z < tt; ++z) {
    long long n, m;
    cin >> n >> m;
    vector<s> a;
    vector<long long> aa(m);
    for (long long i(0); i < m; ++i) {
      long long f, t;
      cin >> f >> t;
      aa[i] = f;
      a.push_back({f, 0, i});
      a.push_back({t, 1, i});
    }
    sort(a.rbegin(), a.rend());
    vector<long long> used(m);
    long long result = 0;
    long long now = 0;
    long long p = -1;
    for (long long i(0); i < 2 * m; ++i) {
      if (a[i].type == 0) {
        n--;
        now += a[i].value;
        p = a[i].value;
        used[a[i].idx] = true;
        result = max(result, now);
      } else {
        long long new_now = 0;
        if (!used[a[i].idx]) {
          if (n == 1 && p != -1) {
            new_now -= p;
            new_now += a[i].value * n;
          } else if (n > 1) {
            new_now += aa[a[i].idx];
            new_now += a[i].value * (n - 1);
          }
        } else if (used[a[i].idx])
          new_now += a[i].value * n;
        result = max(result, now + new_now);
      }
      if (n == 0) break;
    }
    cout << result << endl;
  }
  return 0;
}
