#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long t = 0, dp = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') dp = -1;
    c = getchar();
  }
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  return t * dp;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void write_p(long long x) {
  write(x);
  putchar(' ');
}
const int N = 200005;
pair<int, int> a[N];
int b[N];
int main() {
  int T = read();
  while (T--) {
    long long m = read(), n = read();
    for (int i = 1; i <= n; ++i) a[i].second = read(), a[i].first = read();
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i) b[i] = a[i].second;
    sort(b + 1, b + n + 1);
    int tep = n;
    long long ans = 0, rest = m, alr = 0;
    for (int i = n; i >= 1; --i) {
      while (tep && b[tep] > a[i].first) {
        rest--, alr += b[tep], tep--;
        if (rest == 0) ans = max(ans, alr);
      }
      if (a[i].second < a[i].first)
        if (rest >= 1)
          ans = max(ans, a[i].second + alr + (rest - 1) * a[i].first);
      if (a[i].second >= a[i].first)
        if (rest >= 0) ans = max(ans, a[i].first * rest + alr);
    }
    writeln(ans);
  }
}
