#include<bits/stdc++.h> #define re register #define int long long
usingnamespace std;
constint N = 2e5 + 10,inf = 1e18 + 10; int T,n,m;
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 1) + (r << 3) + (c ^ 48); c = getchar(); } return r * w; }
signedmain(){ T = read(); while (T--){ int Max = -inf,sum = 0,res = 0; n = read(); m = read(); for (re int i = 1;i <= n;i++){ int x,y; x = read(); y = read(); if (x >= 0){ res += sum * y + x * (y + 1) * y / 2; Max = max(Max,res); } else{ int l = max(1ll,min(sum / (-x),y));//注意这里需要与 1 取 max,避免 sum / (-x) 为负数 int del = sum * l + x * (l + 1) * l / 2; Max = max(Max,res + del); res += sum * y + x * (y + 1) * y / 2; Max = max(Max,res); } sum += x * y; } printf("%lld\n",Max); } return0; }