#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > arr(m);
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    arr[i] = {a, b};
  }
  sort((arr).begin(), (arr).end());
  reverse((arr).begin(), (arr).end());
  vector<long long> pref(m + 1);
  for (int i = 0; i < (m); i++) pref[i + 1] = pref[i] + arr[i].first;
  long long ans = 0;
  for (int i = 0; i < (m); i++) {
    auto [a, b] = arr[i];
    long long total = (n - 1) * b + a;
    int j = lower_bound((arr).begin(), (arr).end(), make_pair(b, INT_MIN),
                        greater<pair<int, int> >()) -
            arr.begin();
    j = min(j, n - 1);
    if (j == 0) {
      ans = max(ans, total);
      continue;
    }
    if (j < m and a >= arr[j - 1].first and b < arr[j].first) j++;
    total += pref[j] - j * b;
    if (j != 0 and a >= arr[j - 1].first) total -= a - b;
    ans = max(ans, total);
  }
  cout << ans << "\n";
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  for (int qq = 0; qq < (tt); qq++) solve();
}
