#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> flowers;
vector<int> first_flowers;
vector<long long> pref_sum;
long long answer;
void In() {
  flowers.clear();
  pref_sum.clear();
  first_flowers.clear();
  answer = LLONG_MIN;
  cin >> n >> m;
  flowers.resize(m);
  for (int i = 0; i < m; i++) cin >> flowers[i].first >> flowers[i].second;
}
long long GetPrefSum(int start_index) {
  return pref_sum.back() -
         ((start_index - 1 >= 0) ? pref_sum[start_index - 1] : 0);
}
void Try(int index) {
  auto range = equal_range(first_flowers.begin(), first_flowers.end(),
                           flowers[index].second);
  int less_or_equal = range.second - first_flowers.begin();
  int remaining = m - less_or_equal;
  remaining = min(remaining, n);
  int start_index = m - remaining;
  if (index >= start_index) {
    long long result = GetPrefSum(start_index);
    long long left_take = n - remaining;
    result += left_take * flowers[index].second;
    answer = max(answer, result);
  } else {
    long long result = flowers[index].first;
    int really_remaining = m - less_or_equal;
    really_remaining = min(really_remaining, n - 1);
    start_index = m - really_remaining;
    result += GetPrefSum(start_index);
    long long left_take = n - 1 - really_remaining;
    result += left_take * flowers[index].second;
    answer = max(answer, result);
  }
}
void Solve() {
  sort(flowers.begin(), flowers.end());
  pref_sum.resize(m);
  pref_sum[0] = flowers[0].first;
  for (int i = 1; i < m; i++) pref_sum[i] = flowers[i].first + pref_sum[i - 1];
  first_flowers.resize(m);
  for (int i = 0; i < m; i++) first_flowers[i] = flowers[i].first;
  for (int i = 0; i < m; i++) Try(i);
}
void Out() { cout << answer << '\n'; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    In();
    Solve();
    Out();
  }
}
