#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  x *= f;
  return;
}
template <typename T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
const int MAXN = 100010;
const int inf = 1e9 + 7;
int n, m;
struct node {
  long long a, b;
} a[MAXN];
struct node2 {
  int pos;
  long long val;
} b[MAXN];
int rk[MAXN];
inline bool cmp(node2 x, node2 y) { return x.val < y.val; }
long long val[MAXN], pre[MAXN];
int main() {
  int t;
  read(t);
  while (t--) {
    read(n), read(m);
    for (int i = 1; i <= m; ++i) read(a[i].a), read(a[i].b), b[i] = {i, a[i].a};
    sort(b + 1, b + m + 1, cmp);
    for (int i = 1; i <= m; ++i)
      rk[b[i].pos] = i, val[i] = b[i].val, pre[i] = pre[i - 1] + val[i];
    long long ans = 0;
    for (int i = 1; i <= m; ++i) {
      long long tmp = a[i].a + a[i].b * (n - 1);
      int pos = upper_bound(val + 1, val + m + 1, a[i].b) - val;
      if (pos > m) {
        ans = max(ans, tmp);
        continue;
      }
      pos = max(pos, m - n + 2);
      if (rk[i] >= pos)
        tmp -= a[i].b * (m - pos), tmp += pre[m] - pre[pos - 1] - a[i].a;
      else
        tmp -= a[i].b * (m - pos + 1), tmp += pre[m] - pre[pos - 1];
      ans = max(ans, tmp);
    }
    write(ans), putchar('\n');
  }
  return 0;
}
