#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long l, long long md) {
  a %= md;
  long long res = 1;
  while (l) {
    if (l & 1) res = res * a % md;
    l /= 2;
    a = a * a % md;
  }
  return res;
}
long long binpow(long long a, long long l) {
  long long res = 1;
  while (l) {
    if (l & 1) res = res * a;
    l /= 2;
    a = a * a;
  }
  return res;
}
long long invmod(long long a, long long md) { return powmod(a, md - 2, md); }
long long __set(long long b, long long i) { return b | (1LL << i); }
long long __unset(long long b, long long i) { return b & (~(1UL << i)); }
long long __check(long long b, long long i) { return b & (1LL << i); }
long long mulmod(long long a, long long b, long long md) {
  return (((a % md) * (b % md)) % md + md) % md;
}
long long addmod(long long a, long long b, long long md) {
  return ((a % md + b % md) % md + md) % md;
}
long long submod(long long a, long long b, long long md) {
  return (((a % md - b % md) % md) + md) % md;
}
long long divmod(long long a, long long b, long long md) {
  return mulmod(a, powmod(b, md - 2, md), md);
}
const long long inf = 0xFFFFFFFFFFFFFFFL;
priority_queue<long long, vector<long long>, greater<long long> > pq;
signed main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long> > ab(m);
    for (long long i = 0; i < m; i++) cin >> ab[i].first >> ab[i].second;
    sort((ab).begin(), (ab).end());
    vector<long long> a(m), b(m);
    for (long long i = 0; i < m; i++) a[i] = ab[i].first, b[i] = ab[i].second;
    vector<long long> suf(m, 0);
    suf[m - 1] = a[m - 1];
    for (long long i = m - 2; i >= 0; i--) suf[i] = suf[i + 1] + a[i];
    long long ans = 0;
    for (long long i = 0; i < m; i++) {
      long long lo = lower_bound((a).begin(), (a).end(), b[i]) - a.begin();
      if (lo == m) {
        ans = max(ans, a[i] + (n - 1) * b[i]);
      } else {
        if (m - lo >= n) {
          ans = max(ans, suf[m - n]);
          continue;
        }
        if (i >= lo) {
          ans = max(ans, suf[lo] + (n - (m - lo)) * b[i]);
        } else {
          ans = max(ans, suf[lo] + a[i] + (n - 1 - (m - lo)) * b[i]);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
