#include <bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int maxn = 2e6 + 7;
const int INF = 1e9;
const long long INFF = 1e18;
int t, n, m, a[maxn];
long long sum[maxn], cnt;
struct node {
  int a, b;
} p[maxn];
bool cmp(node a, node b) { return a.a < b.a; }
int main() {
  scanf("%d", &t);
  while (t--) {
    long long ans = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) scanf("%d%d", &p[i].a, &p[i].b);
    sort(p + 1, p + 1 + m, cmp);
    for (int i = 1; i <= m; i++) a[i] = p[i].a, sum[i] = sum[i - 1] + a[i];
    for (int i = 1; i <= m; i++) {
      int pos = distance(a, upper_bound(a + 1, a + 1 + m, p[i].b));
      if (pos > m) {
        cnt = a[i];
        cnt += 1ll * (n - 1) * p[i].b;
      } else {
        if (pos > i) {
          cnt = a[i];
          int cutnum = min(m - pos + 1, n - 1);
          cnt += sum[m] - sum[m - cutnum];
          cnt += 1ll * (n - 1 - cutnum) * p[i].b;
        } else if (pos <= i) {
          cnt = 0;
          int cutnum = min(m - pos + 1, n);
          cnt += sum[m] - sum[m - cutnum];
          cnt += 1ll * (n - cutnum) * p[i].b;
        }
      }
      ans = max(ans, cnt);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
