#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;
pair<long long, long long> tab[100010];
long long pref[100010];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    for (long long i = 1; i <= m; i++) {
      cin >> tab[i].first >> tab[i].second;
    }
    long long ans = 0;
    sort(tab + 1, tab + m + 1);
    reverse(tab + 1, tab + m + 1);
    if (n <= m) {
      for (long long i = 1; i <= n; i++) ans += tab[i].first;
    }
    for (long long i = 1; i <= m; i++) pref[i] = pref[i - 1] + tab[i].first;
    tab[0].first = INFF;
    for (long long i = 1; i <= m; i++) {
      long long l = 0;
      long long r = m;
      while (r - l > 1) {
        long long mid = (l + r) >> 1;
        if (tab[mid].first > tab[i].second)
          l = mid;
        else
          r = mid - 1;
      }
      long long bound;
      if (tab[r].first > tab[i].second)
        bound = r;
      else
        bound = l;
      long long tmp;
      bound = min(bound, n - 1);
      if (bound < i) {
        tmp = pref[bound] + tab[i].first + (n - (bound + 1)) * tab[i].second;
      } else {
        tmp = pref[bound] + (n - bound) * tab[i].second;
      }
      ans = max(ans, tmp);
    }
    cout << ans << endl;
  }
  return 0;
}
