#include #include #include #include #include using namespace std; #define NLIMIT 100000 #define NSLIMIT 1000000 #define ALIMIT 1000000000 #define N NLIMIT + 100 pair a[N]; int main() { int t, nsum = 0; scanf("%d", &t); assert(1 <= t && t <= NLIMIT); while(t--) { int n, m; scanf("%d%d", &n, &m); assert(1 <= n && n <= NLIMIT); assert(0 <= m && m <= n); nsum += n; multiset S; for(int i=0; i