#include <bits/stdc++.h>
using namespace std;
long long queries, n, m, x, y;
long long rez;
vector<pair<long long, long long> > vec;
vector<long long> prefSum;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> queries;
  while (queries--) {
    cin >> n >> m;
    vec.resize(m + 1);
    for (int i = 1; i <= m; i++) cin >> vec[i].first >> vec[i].second;
    sort(vec.begin() + 1, vec.end(),
         [&](const pair<int, int>& i, const pair<int, int>& j) {
           return i > j;
         });
    prefSum.resize(vec.size());
    rez = 0;
    for (int i = 1; i <= m; i++) prefSum[i] = prefSum[i - 1] + vec[i].first;
    for (int i = 1; i <= m; i++) {
      long long st = 1, dr = m, poz = 0;
      while (st <= dr) {
        int mij = (st + dr) / 2;
        if (vec[mij].first < vec[i].second) {
          dr = mij - 1;
        } else {
          poz = mij;
          st = mij + 1;
        }
      }
      poz = min(poz, n);
      if (poz >= i)
        rez = max(rez, prefSum[poz] + (n - poz) * vec[i].second);
      else
        rez = max(rez, prefSum[min(poz, n - 1)] +
                           (n - min(poz, n - 1) - 1) * vec[i].second +
                           vec[i].first);
    }
    cout << rez << "\n";
  }
  return 0;
}
