#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long T, n, m, now, sum, minn, ans;
long long a[N], c[N];
struct number {
  long long x, y;
} num[N];
inline bool cmp(number a, number b) { return a.x < b.x; }
signed main() {
  scanf("%lld", &T);
  while (T--) {
    ans = 0;
    scanf("%lld%lld", &n, &m);
    for (register long long i = 1; i <= m; ++i)
      scanf("%lld%lld", &num[i].x, &num[i].y);
    sort(num + 1, num + m + 1, cmp);
    for (register long long i = 1; i <= m; ++i)
      a[i] = num[i].x, c[i] = c[i - 1] + num[i].x;
    sort(a + 1, a + m + 1);
    for (register long long i = 1; i <= m; ++i) {
      now = n;
      sum = num[i].x;
      now--;
      if (now) {
        long long pos = lower_bound(a + 1, a + m + 1, num[i].y) - a;
        if (pos > m)
          sum += now * num[i].y;
        else {
          minn = min(m - pos + 1, now);
          sum += c[m] - c[m - minn];
          now -= minn;
          if (m - minn + 1 <= i && i <= m) sum -= num[i].x, now++;
          sum += now * num[i].y;
        }
      }
      ans = max(ans, sum);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
