#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 3;
int t;
long long m, n;
pair<long long, long long> v[MX];
long long p[MX];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld %lld", &n, &m);
    long long ans = 0;
    for (int i = 0; i < m; i++) {
      scanf("%lld %lld", &v[i].first, &v[i].second);
    }
    sort(v, v + m, greater<pair<long long, long long>>());
    for (int i = 0; i < m; i++) {
      p[i] = v[i].first + (i ? p[i - 1] : 0);
      if (i < n) ans += v[i].first;
    }
    for (int i = 0; i < m; i++) {
      int l = 0;
      int r = m - 1;
      int md;
      while (l != r) {
        md = (l + r) / 2;
        if (v[md].first < v[i].second)
          r = md;
        else
          l = md + 1;
      }
      int cnt = l;
      if (v[m - 1].first >= v[i].second) cnt++, l++;
      long long sum = 0;
      if (l) sum = p[l - 1];
      if (l > i && cnt) {
        cnt--;
        sum -= v[i].first;
      }
      if (cnt > n - 2) {
        continue;
      }
      long long ret = v[i].first + v[i].second * (n - cnt - 1) + sum;
      ans = max(ans, ret);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
