#include <bits/stdc++.h> #define int long long
using namespace std;
signed main() { ios::sync_with_stdio(false); cin.tie(0);
int t; cin >> t;
while (t --)
{
int n, m; cin >> n >> m;
int sum = 0;
vector<int> p;
for (int i = 0; i < n; i ++)
{
int x; cin >> x;
sum += x;
if (x > 0) p.push_back(x * (n - i));
}
sort(p.begin(), p.end());
for (int i = p.size() - 1; ~i && m; i --) sum -= p[i], m --;
cout << sum << "\n";
}
return 0;
}