#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    int temp;
    pair<long long, long long> v[m + 1];
    for (temp = 1; temp <= m; temp++) {
      cin >> v[temp].first >> v[temp].second;
    }
    sort(v + 1, v + m + 1);
    long long pref[m + 2];
    pref[0] = 0;
    for (int temp = 1; temp <= m; temp++) {
      pref[temp] = pref[temp - 1] + v[temp].first;
    }
    pref[m + 1] = pref[m];
    long long mx = 0;
    for (int temp = m; temp >= 1; temp--) {
      long long second = v[temp].second;
      long long first = v[temp].first;
      int theInd = m + 1;
      int left = max(1, m - n + 1), right = m;
      while (left <= right) {
        int mid = (left + right) >> 1;
        if (v[mid].first > second) {
          theInd = mid;
          right = mid - 1;
        } else
          left = mid + 1;
      }
      long long indSum = pref[m] - pref[theInd - 1];
      long long len = m - theInd + 1;
      if (theInd > temp) {
        indSum += first;
        len++;
      }
      if (len > n) {
        indSum -= v[theInd].first;
        len--;
      }
      if (len > n) continue;
      mx = max(mx, indSum + 1ll * (n - len) * second);
    }
    cout << mx << "\n";
  }
}
