#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll = long long;
using ld = long double;
#define all(array) array.begin(), array.end()
constexpr long long INF =  (long long)2e18 + 1;
constexpr ll inf = 1e9 + 1;
const ll mod = 1e9 + 7;



void solve(){
    ll n, k ;
    cin >> n >> k;
    vector<ll> v(n);
    ll ans = 0;
    vector<pair<ll,ll>> p(n);
    for(int i = 0 ;i < n; ++i){
        cin >> v[i];
        p[i] = {v[i], i};
    }
    sort(all(p));
    for(ll t =  0 ; t < 1000; ++ t){
    if(n- t < k){
        break;
    }
    ll sum = 0;
    vector<ll > pos(n);
    ll c=  0;
    for(ll i =  n - 1; i >= 0; --i){
        if(c == k-1) break;
        if(p[i].second < n- t -1){
        sum += p[i].first;
        pos[p[i].second] = 1;
        c ++;
        }

    }
    ll cnt = 0;
    ll mx = v[n-t-1] + n-t;
    ans = max(ans, mx + sum);}
    ll q = 0;
    cout << ans;
}


signed main(){
    fast;;;
    long long tc = 1;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> tc;
#endif
    while(tc--){
        solve()
        ;
        cout << "\n";
    }


}