#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 69;
const long long base = 311;
string t = "abacaba";
string s;
pair<long long, long long> a[maxn];
long long n, m;
long long st[4 * maxn];
long long st1[4 * maxn];
long long get(long long id, long long left, long long right, long long x,
              long long y) {
  if (left > y || right < x) return 0;
  if (x <= left && right <= y) {
    return st[id];
  }
  long long mid = (left + right) / 2;
  return get(id * 2, left, mid, x, y) + get(id * 2 + 1, mid + 1, right, x, y);
}
void update(long long id, long long left, long long right, long long pos,
            long long diff) {
  if (pos < left || pos > right) return;
  if (left == right) {
    st[id] = diff;
    return;
  }
  long long mid = (left + right) / 2;
  update(id * 2, left, mid, pos, diff);
  update(id * 2 + 1, mid + 1, right, pos, diff);
  st[id] = st[id * 2] + st[id * 2 + 1];
}
long long get1(long long id, long long left, long long right, long long x,
               long long y) {
  if (left > y || right < x) return 0;
  if (x <= left && right <= y) {
    return st1[id];
  }
  long long mid = (left + right) / 2;
  return max(get1(id * 2, left, mid, x, y),
             get1(id * 2 + 1, mid + 1, right, x, y));
}
void update1(long long id, long long left, long long right, long long pos,
             long long diff) {
  if (pos < left || pos > right) return;
  if (left == right) {
    st1[id] = diff;
    return;
  }
  long long mid = (left + right) / 2;
  update1(id * 2, left, mid, pos, diff);
  update1(id * 2 + 1, mid + 1, right, pos, diff);
  st1[id] = max(st1[id * 2], st1[id * 2 + 1]);
}
vector<pair<long long, long long> > nw;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t1;
  cin >> t1;
  while (t1--) {
    cin >> m >> n;
    nw.clear();
    for (int i = 1; i <= n; i++) {
      cin >> a[i].first >> a[i].second;
      nw.push_back(make_pair(a[i].first, a[i].second));
    }
    sort(nw.begin(), nw.end());
    reverse(nw.begin(), nw.end());
    for (int i = 0; i < n; i++) {
      update(1, 1, n, i + 1, nw[i].first);
      update1(1, 1, n, i + 1, nw[i].first);
    }
    if (m == 1) {
      cout << nw[0].first << "\n";
      continue;
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      long long l = 1, h = n;
      update(1, 1, n, i + 1, 0);
      while (l <= h) {
        long long mid = (l + h) / 2;
        long long k = nw[mid - 1].first;
        if (k >= nw[i].second) {
          l = mid + 1;
        } else {
          h = mid - 1;
        }
      }
      long long mx = nw[i].first;
      long long p = min(m - 1, h);
      p = min(p, n);
      long long cl = m - 1 - p;
      if (p >= i + 1) {
        cl++;
      }
      mx = mx + cl * nw[i].second;
      mx = mx + get(1, 1, n, 1, p);
      ans = max(ans, mx);
      update(1, 1, n, i + 1, nw[i].first);
    }
    cout << ans << "\n";
  }
}
