#include <bits/stdc++.h>
using namespace std;
inline string toString(long long x) {
  string ans = "";
  bool negtive = x < 0;
  while (x) ans.push_back(x % 10 + '0'), x /= 10;
  if (ans.size() == 0) ans = "0";
  if (negtive) ans.push_back('-');
  for (long long i = 0; i < ans.size() / 2; i++)
    swap(ans[i], ans[ans.size() - 1 - i]);
  return ans;
}
inline long long toInt(const string &str) {
  long long ans = 0;
  bool negtive = str[0] == '-';
  for (long long i = negtive; i < str.size(); i++)
    ans = ans * 10 + str[i] - '0';
  if (negtive) ans *= -1;
  return ans;
}
inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d = a;
  if (b == 0)
    x = 1, y = 0;
  else {
    d = exgcd(b, a % b, y, x), y -= a / b * x;
  }
  return d;
}
const long long mod = 1e9 + 7;
inline long long rd() {
  register signed ans = 0;
  char last = ' ', ch = getchar();
  while (!(ch >= '0' && ch <= '9')) last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9')
    ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar();
  return ans;
}
inline long long QPow(long long a, long long b) {
  long long ans = 1;
  if (b < 0) return 0;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
inline long long QPow(long long a, long long b, const long long &mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
const long double PI = 3.141592653589793115997963468544185161590576171875;
const long double eps = 1e-7;
const long double e = 2.718281828459045;
void ask(long long x, long long y) {
  cout << "? " << x << ' ' << y << endl;
  cout.flush();
  ;
}
void decide(long long x) {
  cout << "! " << x << endl;
  cout.flush();
  ;
}
const long long maxn = 1e5 + 5;
pair<signed, signed> p[maxn];
long long id[maxn];
bool vis[maxn];
long long Max[maxn << 2];
long long suf[maxn];
inline void pushup(long long rt) {
  Max[rt] = max(Max[(rt << 1)], Max[(rt << 1 | 1)]);
}
void build(long long l, long long r, long long rt) {
  Max[rt] = 0;
  if (l != r)
    build(l, ((l + r) >> 1), (rt << 1)),
        build(((l + r) >> 1) + 1, r, (rt << 1 | 1));
}
inline void update(long long l, long long r, long long rt, long long pos,
                   long long val) {
  if (l == r) {
    Max[rt] = val;
    return;
  }
  if (pos <= ((l + r) >> 1)) update(l, ((l + r) >> 1), (rt << 1), pos, val);
  if (pos > ((l + r) >> 1))
    update(((l + r) >> 1) + 1, r, (rt << 1 | 1), pos, val);
  pushup(rt);
}
inline long long query(long long l, long long r, long long rt, long long L,
                       long long R) {
  if (L <= l && r <= R) return Max[rt];
  long long ans = 0;
  if (L <= ((l + r) >> 1))
    ans = max(ans, query(l, ((l + r) >> 1), (rt << 1), L, R));
  if (R > ((l + r) >> 1))
    ans = max(ans, query(((l + r) >> 1) + 1, r, (rt << 1 | 1), L, R));
  return ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long t = 1;
  srand(time(0));
  long long n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 1; i <= m; i++) cin >> p[i].first >> p[i].second;
    sort(p + 1, p + 1 + m);
    for (long long i = 1; i <= m; i++) suf[i] = p[i].first;
    for (long long i = m - 1; i >= 1; i--) suf[i] += suf[i + 1];
    for (long long i = 1; i <= m; i++) id[i] = p[i].first;
    long long ans = 0;
    for (long long i = 1; i <= m; i++) {
      long long curAns = 0;
      signed idx = lower_bound(id + 1, id + 1 + m, p[i].second) - id;
      long long tot = n;
      if (idx > i) {
        curAns += p[i].first;
        tot--;
        long long num = min(n - 1, m - idx + 1);
        tot -= num;
        curAns += suf[m + 1 - num];
        curAns += p[i].second * tot;
      } else {
        long long num = min(n, m - idx + 1);
        tot -= num;
        curAns += suf[m + 1 - num];
        curAns += p[i].second * tot;
      }
      ans = max(ans, curAns);
    }
    cout << ans << '\n';
    for (long long i = 0; i <= m + 1; i++) suf[i] = 0;
    for (long long i = 1; i <= m; i++) vis[i] = 0;
  }
  return 0;
}
