#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<long long, long long> x[maxn];
long long sum[maxn], res, ans, n;
int m;
int _find(long long v) {
  int l = 1, r = m, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (x[mid].first > v) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    ans = 0;
    sum[0] = 0;
    scanf("%lld%d", &n, &m);
    for (int i = 1; i <= m; i++) scanf("%lld%lld", &x[i].first, &x[i].second);
    sort(x + 1, x + 1 + m, greater<pair<long long, long long>>());
    for (int i = 1; i <= m; i++) sum[i] = sum[i - 1] + x[i].first;
    for (int i = 1; i <= m; i++) {
      int ind = _find(x[i].second);
      long long cnt = min((long long)ind, n - 1ll);
      res = sum[cnt];
      long long b = n - cnt;
      if (i > cnt) {
        res += x[i].first;
        b--;
      }
      res += b * x[i].second;
      ans = max(res, ans);
    }
    printf("%lld\n\n", ans);
  }
  return 0;
}
