#include <bits/stdc++.h>
using namespace std;
bool vis[1000000 + 10];
struct node {
  long long x, y;
} a[1000000 + 10];
bool cmp(node a, node b) { return a.x > b.x; }
long long sum[1000000 + 10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = (1); i < (m + 1); i++) cin >> a[i].x >> a[i].y;
    long long ans = 0;
    sort(a + 1, a + 1 + m, cmp);
    for (int i = (1); i < (m + 1); i++) {
      sum[i] = sum[i - 1] + a[i].x;
    }
    for (int i = (1); i < (m + 1); i++) {
      int l = 1, r = m;
      int pos = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (a[mid].x > a[i].y) {
          pos = max(pos, mid);
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      if (pos >= n) {
        ans = max(ans, sum[n]);
        continue;
      }
      if (a[i].x > a[i].y)
        ans = max(ans, sum[pos] + (long long)max(0, (n - pos)) * a[i].y);
      else
        ans =
            max(ans, sum[pos] + 1ll * max(0, (n - pos - 1)) * a[i].y + a[i].x);
    }
    cout << ans << "\n";
  }
  return 0;
}
