#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<int, int> &x, const pair<int, int> &y) {
  return x.first > y.first || (x.first == y.first && x.second > y.second);
}
int a[100010], c[100010];
pair<int, int> pa[100010], pc[100010];
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &m, &n);
    for (int i = (1); i <= (n); ++i) {
      scanf("%d%d", a + i, c + i);
      pa[i] = make_pair(a[i], c[i]);
      pc[i] = make_pair(c[i], a[i]);
    }
    sort(pa + 1, pa + n + 1, cmp);
    sort(pc + 1, pc + n + 1, cmp);
    int j = 1, max_c = 0;
    long long sum_a = 0, ans = 0;
    for (int i = (1); i <= (n); ++i) {
      while (j <= n && j <= m && pa[j].first >= pc[i].first) {
        sum_a += pa[j].first;
        max_c = max(max_c, pa[j].second);
        ans = max(ans, sum_a + (long long)max_c * (m - j));
        j++;
      }
      if (j > m) break;
      if (pc[i].second < pc[i].first)
        ans = max(ans, sum_a + pc[i].second + (long long)pc[i].first * (m - j));
    }
    printf("%lld\n", ans);
  }
  return 0;
}
