func_code_string: #include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int t;   long long sufa[100010];   long long a[100010];   pair<long long, long long> ab[100010];   long long n, m;   int main() {     cin >> t;     while (t--) {       scanf( %lld %lld , &n, &m);       for (long long i = 0; i < m; i++) {         scanf( %lld %lld , &ab[i].first, &ab[i].second);       }       sort(ab, ab + m);       sufa[m] = 0;       sufa[m - 1] = a[m - 1] = ab[m - 1].first;       for (int i = m - 1 - 1; i >= 0; i--) {         a[i] = ab[i].first;         sufa[i] = sufa[i + 1] + a[i];       }       long long ans = 0;       if (n <= m) {         ans = sufa[m - n];       }       for (long long i = 0; i < m; i++) {         long long idx = lower_bound(a, a + m, ab[i].second) - a;         idx = max(idx, m - n);         long long costn = m - idx;         long long costa = 0;         if (idx > i && costn < n) {           costa = ab[i].first;           costn += 1;         }         ans = max(ans, sufa[idx] + costa + (n - costn) * ab[i].second);       }       printf( %lld n , ans);     }     return 0;   }   