#include <bits/stdc++.h>
void solve() {
  using Flower = std::pair<int, int>;
  int n, m;
  std::cin >> n >> m;
  std::vector<Flower> flows(m);
  for (Flower& f : flows) std::cin >> f.first >> f.second;
  std::sort(flows.begin(), flows.end());
  std::vector<int64_t> aSuffSum(m + 1, 0);
  for (int cnt = 1; cnt <= m; cnt++) {
    aSuffSum[cnt] = aSuffSum[cnt - 1] + flows[m - cnt].first;
  }
  int64_t best = 0;
  for (auto curr = flows.begin(); curr != flows.end(); ++curr) {
    auto first_available =
        std::lower_bound(flows.begin(), flows.end(), Flower{curr->second, -1});
    int top_avaliable = flows.end() - first_available;
    bool curr_included = (first_available <= curr);
    int empty_a_count = std::min(n - 1, top_avaliable - curr_included);
    int b_count = n - 1 - empty_a_count;
    int64_t ans = (int64_t)b_count * curr->second;
    if (curr_included)
      ans += aSuffSum[empty_a_count + 1];
    else
      ans += aSuffSum[empty_a_count] + curr->first;
    best = std::max(best, ans);
  }
  std::cout << best << "\n";
}
int main() {
  int tests;
  std::cin >> tests;
  for (int i = 0; i < tests; i++) {
    solve();
  }
}
