#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long a[maxn], b[maxn], v[maxn];
long long sum[maxn << 2], maxs[maxn << 2], nums[maxn << 2];
void build(int id, int l, int r) {
  sum[id] = 0, maxs[id] = 0, nums[id] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
}
void push_up(int id) {
  sum[id] = sum[id << 1] + sum[id << 1 | 1];
  nums[id] = nums[id << 1] + nums[id << 1 | 1];
  maxs[id] = max(maxs[id << 1], maxs[id << 1 | 1]);
}
void update(int id, int l, int r, int pos, long long A, long long B) {
  if (l == r) {
    nums[id]++;
    sum[id] += A;
    maxs[id] = max(maxs[id], B);
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid) update(id << 1, l, mid, pos, A, B);
  if (pos > mid) update(id << 1 | 1, mid + 1, r, pos, A, B);
  push_up(id);
}
long long querySum(int id, int l, int r, int x, int y) {
  if (y < l || x > r) return 0;
  if (x <= l && y >= r) return sum[id];
  long long ans = 0;
  int mid = (l + r) >> 1;
  if (x <= mid) ans += querySum(id << 1, l, mid, x, y);
  if (y > mid) ans += querySum(id << 1 | 1, mid + 1, r, x, y);
  return ans;
}
long long queryMax(int id, int l, int r, int x, int y) {
  if (y < l || x > r) return 0;
  if (x <= l && y >= r) return maxs[id];
  long long ans = 0;
  int mid = (l + r) >> 1;
  if (x <= mid) ans = max(ans, queryMax(id << 1, l, mid, x, y));
  if (y > mid) ans = max(ans, queryMax(id << 1 | 1, mid + 1, r, x, y));
  return ans;
}
long long queryNum(int id, int l, int r, int x, int y) {
  if (y < l || x > r) return 0;
  if (x <= l && y >= r) return nums[id];
  long long ans = 0;
  int mid = (l + r) >> 1;
  if (x <= mid) ans += queryNum(id << 1, l, mid, x, y);
  if (y > mid) ans += queryNum(id << 1 | 1, mid + 1, r, x, y);
  return ans;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, m;
    scanf("%lld%lld", &n, &m);
    for (int i = 1; i <= m; i++) {
      scanf("%lld%lld", &a[i], &b[i]);
      v[i] = a[i];
    }
    sort(v + 1, v + 1 + m);
    int len = unique(v + 1, v + 1 + m) - v - 1;
    build(1, 1, len);
    for (int i = 1; i <= m; i++)
      a[i] = lower_bound(v + 1, v + 1 + len, a[i]) - v;
    for (int i = 1; i <= m; i++) update(1, 1, len, a[i], v[a[i]], b[i]);
    long long ans = 0;
    for (int i = 1; i <= m; i++) {
      int pos = upper_bound(v + 1, v + 1 + len, max(v[a[i]], b[i])) - v;
      long long res = querySum(1, 1, len, pos, len);
      long long num = n - queryNum(1, 1, len, pos, len);
      num--, res += v[a[i]];
      if (num < 0) continue;
      if (v[a[i]] > b[i]) {
        long long xx = queryNum(1, 1, len, a[i], a[i]) - 1;
        res += min(xx, num) * v[a[i]];
        num -= min(xx, num);
      }
      res += max(b[i], queryMax(1, 1, len, pos, len)) * num;
      ans = max(ans, res);
    }
    printf("%lld\n", ans);
  }
}
