#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    deque<long long> a(m);
    deque<long long> b(m);
    for (long long i = 0; i < m; i++) cin >> a[i] >> b[i];
    deque<long long> a2 = a;
    sort(a2.begin(), a2.end());
    a2.push_back(LLONG_MAX);
    a2.push_front(-1);
    reverse(a2.begin(), a2.end());
    long long res = 0;
    vector<long long> prefix(m + 2, 0);
    prefix[0] = 0;
    for (long long i = 1; i < m + 1; i++) prefix[i] = a2[i] + prefix[i - 1];
    for (long long i = 0; i < m; i++) {
      long long low = 0;
      long long high = m + 1;
      while (high - low > 1) {
        long long mid = (high + low) / 2;
        if (a2[mid] <= b[i])
          high = mid;
        else
          low = mid;
      }
      long long greater = low;
      if (a[i] > b[i]) greater--;
      greater = max(greater, 0ll);
      long long curr = a[i];
      if (greater > n - 1) {
        curr += prefix[n - 1];
        if (a2[n - 1] <= a[i]) {
          curr -= a[i];
          curr += max(b[i], a2[n]);
        }
      } else {
        curr += prefix[greater];
        if (a2[greater] <= a[i] && greater != 0) {
          curr -= a[i];
          curr += max(b[i], a2[greater + 1]);
        }
        long long rem = n - 1 - greater;
        curr += rem * b[i];
      }
      if (n == 1) curr = a[i];
      res = max(res, curr);
    }
    cout << res << '\n';
  }
}
