#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  cin >> test;
  for (; test > 0; --test) {
    long long int n, m;
    cin >> n >> m;
    pair<long long int, long long int> arr[m];
    vector<pair<long long int, long long int> > v;
    long long int ps[m + 1];
    for (long long int i = 0; i < m; ++i) {
      long long int f, s;
      cin >> f >> s;
      v.push_back(make_pair(f, i));
      arr[i] = make_pair(f, s);
    }
    long long int ans = 0;
    sort((v).begin(), (v).end());
    ps[m] = 0;
    for (long long int i = m - 1; i >= 0; --i) ps[i] = ps[i + 1] + v[i].first;
    for (long long int i = 0; i < m; ++i) {
      long long int tc = n, pans = arr[i].first, oit;
      auto it = upper_bound((v).begin(), (v).end(),
                            make_pair(arr[i].second, -1 * 1LL)) -
                v.begin();
      auto it1 =
          lower_bound((v).begin(), (v).end(), make_pair(arr[i].first, i)) -
          v.begin();
      oit = it;
      it = min(tc, m - 1 - (it) + 1);
      if (m - it <= it1)
        pans -= arr[i].first;
      else {
        tc--;
        it = min(tc, m - 1 - (oit) + 1);
      }
      if (it > 0) {
        pans += ps[m - it];
        tc -= it;
      }
      pans += tc * arr[i].second;
      ans = max(ans, pans);
    }
    cout << ans << endl;
  }
  return (0);
}
