#include <bits/stdc++.h>
using namespace std;
struct a {
  long long int first;
  long long int second;
} g[100005];
bool cmp(struct a pp, struct a pp1) {
  if (pp.first == pp1.first) return pp.second < pp1.second;
  return pp.first < pp1.first;
}
long long int c[100005];
long long int sum[100005];
long long int max1(long long int kk, long long int kk1) {
  if (kk > kk1) return kk;
  return kk1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(sum, 0, sizeof(sum));
    memset(c, 0, sizeof(c));
    long long int n, m;
    scanf("%lld%lld", &n, &m);
    for (int i = 1; i <= m; i++) {
      scanf("%lld%lld", &g[i].first, &g[i].second);
    }
    sort(g + 1, g + 1 + m, cmp);
    for (int i = 1; i <= m; i++) {
      sum[i] = sum[i - 1] + g[i].first;
      c[i] = g[i].first;
    }
    long long int price = 0;
    if (n <= m) price = sum[m] - sum[m - n];
    for (int i = m; i >= 1; i--) {
      long long int sp = g[i].second;
      long long int llmaxsecond = 0;
      long long int price2 = 0;
      long long int price1 = 0;
      long long int num = 0;
      long long int pos = lower_bound(c + 1, c + m + 1, sp) - c;
      num = m - pos + 1;
      if (n >= num) {
        long long int temp;
        if (pos > i)
          temp = g[i].first - g[i].second;
        else
          temp = 0;
        price = max1(price, sum[m] - sum[pos - 1] +
                                1ll * (n - num) * g[i].second + temp);
      }
    }
    printf("%lld\n", price);
  }
}
