#include <bits/stdc++.h>
using namespace std;
bool comp1(pair<long long int, long long int> p1,
           pair<long long int, long long int> p2) {
  if (p1.second > p2.second) {
    return true;
  }
  if (p1.second == p2.second) {
    if (p1.first > p2.first) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<pair<long long int, long long int> > pairs(m);
    for (int i = 0, colchin = m; i < colchin; ++i) {
      long long int a, b;
      cin >> a >> b;
      pairs[i] = {a, b};
    }
    sort(pairs.begin(), pairs.end());
    vector<long long int> a(m);
    for (int i = 0, colchin = m; i < colchin; ++i) a[i] = pairs[i].first;
    vector<long long int> preSum(m);
    preSum[m - 1] = pairs[m - 1].first;
    for (int i = m - 2; i >= 0; i--) {
      preSum[i] = preSum[i + 1] + pairs[i].first;
    }
    long long int ans = 0;
    for (int i = 0, colchin = m; i < colchin; ++i) {
      long long int curB = pairs[i].second;
      auto it = upper_bound(a.begin(), a.end(), curB);
      int lo = it - a.begin();
      if (m - lo > n) {
        lo = m - n;
      }
      long long int temp = 0;
      if (lo < m) {
        temp = preSum[lo];
      }
      if (n - (m - lo) > 0) {
        int cant = n - (m - lo);
        if (lo <= i) {
          temp += (cant * pairs[i].second);
        } else {
          temp += pairs[i].first + ((cant - 1) * pairs[i].second);
        }
      }
      ans = max(ans, temp);
    }
    cout << ans << "\n";
  }
  return 0;
}
