#include <bits/stdc++.h>
using namespace std;
long long int t;
string p = "abacaba";
string p1;
long long int check(string s, long long int ind) {
  p1 = s;
  if (p1.substr(ind, 7) == p) return true;
  for (long long int i = ind; i < ind + 7; i++) {
    if (p1[i] != p[i - ind] && p1[i] != '?') {
      return false;
    } else
      p1[i] = p[i - ind];
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    vector<pair<long long int, long long int>> a(m + 1);
    vector<long long int> a1(m + 1), c(m + 2, 0);
    long long int ans = 0;
    for (long long int i = 1; i <= m; i++) {
      cin >> a[i].second >> a[i].first;
      a1[i] = a[i].second;
    }
    sort(a1.begin() + 1, a1.begin() + m + 1);
    for (long long int i = m; i >= 1; i--) c[i] = c[i + 1] + a1[i];
    for (long long int i = 1; i <= m; i++) {
      long long int t1 = a[i].first, t2 = a[i].second;
      long long int ind =
          lower_bound(a1.begin() + 1, a1.begin() + m + 1, t1) - a1.begin();
      long long int nos = m - ind + 1;
      long long int ans1 = c[max(ind, m - n + 1)];
      if (nos >= n) {
        ans = max(ans, ans1);
        continue;
      }
      ans1 += (n - nos - 1) * t1 + t2;
      if (t2 >= t1) ans1 -= t2, ans1 += t1;
      ans = max(ans, ans1);
    }
    cout << ans << "\n";
  }
}
