#include <bits/stdc++.h>
using namespace std;
struct graphNode {
  int curr, weight;
  graphNode* next;
};
struct graphEdge {
  int start, terminal, weight;

 public:
  graphEdge() {}
  graphEdge(int start, int terminal, int weight) {
    this->start = start;
    this->terminal = terminal;
    this->weight = weight;
  }
};
struct DiaGraph {
  graphNode* getGraphNode(int curr, int weight, graphNode* head) {
    graphNode* newNode = new graphNode;
    newNode->curr = curr;
    newNode->weight = weight;
    newNode->next = head;
    return newNode;
  }
  int vertices;

 public:
  graphNode** head;
  DiaGraph(graphEdge edges[], int edg, int vert) {
    head = new graphNode*[vert + 1]();
    this->vertices = vert;
    for (int i = 1; i <= vert; i++) {
      head[i] = nullptr;
    }
    for (int i = 1; i <= edg; i++) {
      int start = edges[i].start;
      int terminal = edges[i].terminal;
      int weight = edges[i].weight;
      graphNode* newNode = getGraphNode(terminal, weight, head[start]);
      head[start] = newNode;
    }
  }
  ~DiaGraph() {
    for (int i = 0; i <= vertices; i++) {
      delete[] head[i];
      delete[] head;
    }
  }
};
DiaGraph getUndirGraph(int n, int m) {
  graphEdge edges[2 * m + 1];
  for (int i = 1; i <= m; i++) {
    int start, terminal, weight = 1;
    cin >> start >> terminal;
    graphEdge* edge1 = new graphEdge(start, terminal, weight);
    graphEdge* edge2 = new graphEdge(terminal, start, weight);
    edges[i] = *edge1;
    edges[i + m] = *edge2;
  }
  DiaGraph graph(edges, 2 * m, n);
  return graph;
}
const int N = 1e5 + 7;
int n, m, a[N], srta[N], b[N];
long long prea[N];
int bs(int tar) {
  int p1 = 1, p2 = m;
  int val = -1;
  while (p1 <= p2) {
    int mid = (p1 + p2) / 2;
    if (srta[mid] >= tar) {
      p1 = mid + 1;
      val = mid;
    } else if (srta[mid] < tar) {
      p2 = mid - 1;
    }
  }
  return val;
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
    srta[i] = a[i];
    cin >> b[i];
  }
  sort(srta + 1, srta + m + 1, greater<int>());
  for (int i = 1; i <= m; i++) prea[i] = prea[i - 1] + srta[i];
  long long sum = 0;
  for (int i = 1; i <= m; i++) {
    long long csum = 0;
    int aidx = bs(b[i]);
    int rem = n;
    aidx = min(rem, aidx);
    if (aidx != -1) {
      csum += prea[aidx];
      rem -= aidx;
      if (aidx > 0 && a[i] < srta[aidx] && rem > 0) csum += a[i], rem -= 1;
      rem = max(rem, 0);
      csum += rem * 1ll * b[i];
    }
    long long nsum = 0;
    nsum = a[i] + (n - 1) * 1ll * b[i];
    sum = max(sum, csum);
    sum = max(sum, nsum);
  }
  if (n <= m) sum = max(sum, prea[n]);
  cout << sum << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
