#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long binary_exp(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = ((ans * a)) % MOD;
    }
    a = (a * a) % MOD;
    b = b >> 1;
  }
  return ans % MOD;
}
long long gcd(long long a, long long b) {
  if (a < b) {
    return gcd(b, a);
  } else {
    if (b == 0) {
      return a;
    } else {
      return gcd(b, a % b);
    }
  }
}
void dfs(long long i, vector<vector<long long> > &adj, vector<long long> &vis) {
  vis[i] = 1;
  for (auto j : adj[i]) {
    if (vis[j] == false) {
      dfs(j, adj, vis);
    }
  }
}
bool check(string s, long long n, string t) {
  long long count = 0;
  for (long long i = 0; i <= n - 7; i++) {
    if (s.substr(i, 7) == t) {
      count++;
    }
  }
  if (count == 1) {
    return true;
  } else {
    return false;
  }
}
bool comp(tuple<long long, long long, long long> &a,
          tuple<long long, long long, long long> &b) {
  if (get<0>(a) > get<0>(b)) {
    return true;
  } else if (get<0>(a) == get<0>(b)) {
    if (get<1>(a) < get<1>(b)) {
      return true;
    }
  }
  return false;
}
map<tuple<long long, long long, long long>, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    vector<tuple<long long, long long, long long> > v;
    vector<long long> p(m, false);
    vector<pair<long long, long long> > p1(m);
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      p1[i] = {a, b};
      v.push_back({a, 0, i});
      v.push_back({b, 1, i});
    }
    sort(v.begin(), v.end(), comp);
    long long ans = 0;
    long long ans1 = 0;
    long long temp = 0;
    long long count = 0;
    for (long long i = 0; i < v.size(); i++) {
      temp = 0;
      if (get<1>(v[i]) == 0) {
        ans += get<0>(v[i]);
        count++;
        ans1 = max(ans, ans1);
        if (count == n) {
          break;
        }
        p[get<2>(v[i])] = true;
      } else {
        if (p[get<2>(v[i])] == true) {
          temp = ans + ((n - count) * get<0>(v[i]));
        } else {
          temp =
              ans + p1[get<2>(v[i])].first + ((n - count - 1) * get<0>(v[i]));
        }
      }
      ans1 = max(temp, ans1);
    }
    cout << ans1 << endl;
  }
  return 0;
}
