#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int t, n, m;
  long long int ans;
  cin >> t;
  while (t--) {
    ans = 0;
    cin >> n >> m;
    vector<pair<long long int, long long int>> v(m);
    for (int i = 0; i < m; ++i) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), greater<pair<int, int>>());
    vector<long long int> vclone(m);
    for (int i = 0; i < m; ++i) vclone[i] = v[i].first;
    vector<long long int> prefix_sum(m);
    prefix_sum[0] = v[0].first;
    for (int i = 1; i < m; ++i) prefix_sum[i] = prefix_sum[i - 1] + v[i].first;
    for (int i = 0; i < m; ++i) {
      int idx = upper_bound(vclone.begin(), vclone.end(), v[i].second,
                            greater<int>()) -
                vclone.begin();
      if (idx >= n)
        ans = max(ans, prefix_sum[n - 1]);
      else {
        long long int ts = 0;
        if (idx - 1 >= 0) ts = prefix_sum[idx - 1];
        if (i < idx)
          ans = max(ans, ts + (n - idx) * v[i].second);
        else
          ans = max(ans, ts + v[i].first + (n - idx - 1) * v[i].second);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
