#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> num[100005];
long long sum[100005];
bool cmp(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); }
int main() {
  int t;
  scanf("%d", &t);
  for (int i = (1); i <= (t); i++) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int j = (1); j <= (m); j++) {
      int u, v;
      scanf("%d %d", &u, &v);
      num[j] = {u, v};
    }
    sort(num + 1, num + m + 1, cmp);
    sum[m + 1] = 0;
    for (int j = (m); j >= (1); j--) sum[j] = sum[j + 1] + num[j].first;
    long long ans = 0;
    for (int j = (1); j <= (m); j++) {
      int l = 1, r = m;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (num[mid].first <= num[j].second)
          l = mid + 1;
        else
          r = mid - 1;
      }
      int mxl = m - (n - 1) + 1;
      l = max(l, mxl - (j >= mxl - 1));
      bool inc = 0;
      if (l <= j) inc = 1;
      ans = max(ans, num[j].first * !inc + sum[l] +
                         num[j].second * (n - (m - l + 1) - !inc));
    }
    printf("%lld\n", ans);
  }
  return 0;
}
