#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= 48 && ch <= 57)
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s * w;
}
const long long N = 4e5 + 5;
long long T, n, m, tot, cnt, a[N], b[N], d[N], a1[N], b1[N], a2[N], s[N];
struct node {
  long long val, op, val2;
  inline bool operator<(const node &rhs) const { return val < rhs.val; }
};
priority_queue<node> q;
long long c[N][2];
inline void modify(long long t, long long x, long long k) {
  while (x <= cnt) c[x][t] += k, x += (x & -x);
}
inline long long query(long long t, long long x) {
  long long res = 0;
  while (x > 0) {
    res += c[x][t];
    x -= (x & -x);
  }
  return res;
}
signed main() {
  T = read();
  while (T--) {
    n = read(), m = read();
    tot = 0;
    long long ans = 0;
    for (register long long i = 1; i <= m; ++i) {
      a[i] = read(), b[i] = read();
      d[++tot] = a[i];
      d[++tot] = b[i];
      a2[i] = a[i];
    }
    sort(d + 1, d + tot + 1);
    cnt = unique(d + 1, d + tot + 1) - d - 1;
    for (register long long i = 1; i <= cnt; ++i) c[i][0] = c[i][1] = 0;
    for (register long long i = 1; i <= m; ++i) {
      a1[i] = lower_bound(d + 1, d + cnt + 1, a[i]) - d;
      b1[i] = lower_bound(d + 1, d + cnt + 1, b[i]) - d;
      modify(0, a1[i], a[i]);
      modify(1, a1[i], 1);
    }
    sort(a2 + 1, a2 + m + 1, greater<long long>());
    s[0] = 0;
    for (register long long i = 1; i <= m; ++i) s[i] = s[i - 1] + a2[i];
    for (register long long i = 1; i <= m; ++i) {
      long long x = query(0, cnt) - query(0, b1[i]);
      long long y = query(1, cnt) - query(1, b1[i]);
      if (y >= n) {
        ans = max(ans, s[n]);
      } else {
        if (a[i] > b[i]) {
          ans = max(ans, x + (n - y) * b[i]);
        } else {
          ans = max(ans, x + a[i] + (n - y - 1) * b[i]);
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
