#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
class Div_657_C {
 private:
  int n, m;
  vector<long long> a, b;
  vector<long long> new_a, new_b;
  vector<long long> pref;

 public:
  Div_657_C(int n, int m) {
    this->n = n;
    this->m = m;
    a.resize(m);
    b.resize(m);
    pref.resize(m + 1, 0);
  }
  void init() {
    for (int i = 0; i < m; ++i) {
      cin >> a[i] >> b[i];
    }
  }
  void make_new() {
    new_a = a;
    sort((new_a).begin(), (new_a).end());
    for (int i = 0; i < m; ++i) {
      pref[i + 1] = pref[i] + new_a[i];
    }
  }
  void solve() {
    long long res = 0;
    for (int i = 0; i < m; ++i) {
      int idx =
          upper_bound((new_a).begin(), (new_a).end(), b[i] - 1) - new_a.begin();
      int rem = m - idx;
      if (rem >= n) {
        res = max(res, pref[m] - pref[m - n]);
        continue;
      }
      if (a[i] >= b[i]) {
        int taken = m - idx;
        int rem = n - taken;
        long long now = (pref[m] - pref[idx]) + (1LL * rem * b[i]);
        res = max(res, now);
      } else {
        int taken = m - idx;
        int rem = (n - 1) - taken;
        long long now = a[i] + (pref[m] - pref[idx]) + (1LL * rem * b[i]);
        res = max(res, now);
      }
    }
    cout << res << endl;
  }
  void display() {
    for (int i = 0; i < m; ++i) {
      cout << a[i] << " " << b[i] << endl;
    }
  }
};
void HalfDead() {
  Div_657_C *obj;
  int n, m;
  cin >> n >> m;
  obj = new Div_657_C(n, m);
  obj->init();
  obj->make_new();
  obj->solve();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    HalfDead();
  }
  return 0;
}
