func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pr = pair<int, int>;   using prll = pair<long, long>;   using V = vector<int>;   using Vll = vector<long long>;   template <typename T, typename TT>   pr operator+(pair<T, TT> a, pair<T, TT> b) {     return {a.first + b.first, a.second + b.second};   }   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (auto itr : t) s << itr <<    ;     return s;   }   int n, m;   vector<pair<int, int>> a(200000);   vector<long long> c(100000);   int binSearch(int x) {     int beg = 0;     int last = m - 1;     while (beg < last) {       int mid = beg + (last - beg + 1) / 2;       if (a[mid].first < x)         last = mid - 1;       else         beg = mid;     }     if (a[beg].first < x) return -1;     return beg;   }   bool cmp(pr a, pr b) {     if (a.first == b.first) return a.second > b.second;     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 0; i < int(m); i++) {         int x, y;         cin >> x >> y;         a[i] = {x, y};       }       sort(a.begin(), a.begin() + m, cmp);       c[0] = a[0].first;       for (int i = 0; i < int(m - 1); i++) c[i + 1] = c[i] + a[i + 1].first;       ll ans = INT_MIN;       ans = c[min(n, m) - 1];       for (int i = 0; i < int(m); i++) {         int beg = binSearch(a[i].second);         int t = min(beg, n - 3);         if (beg >= i) t = min(beg, n - 2);         if (t < 0)           ans = max(ans, a[i].first + (n - 1) * 1LL * a[i].second);         else if (t >= i)           ans = max(ans, c[t] + (n - t - 1) * 1LL * a[i].second);         else           ans = max(ans, c[t] + (n - t - 2) * 1LL * a[i].second + a[i].first);       }       cout << ans <<   n ;     }     return 0;   }   