#include #include #include using namespace std; #define ll __int64 ll a[1000000]; int main() { int t; scanf("%d",&t); while(t--) { ll n,k; memset(a,0,sizeof(a)); scanf("%I64d%I64d",&n,&k); for(int i=0;i=n) { printf("%I64d\n",n); continue; } ll tmp=k-1; ll output=0; sort(a,a+n-1); for(int i=n-2-tmp;i>=0;i--) { output+=a[i]+1; } output+=k; printf("%I64d\n",output); } }