#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, i};
    }
    sort(all(p));
    // 111
    ll c = 0;
    ll sum = 0;
    ll ind = p[n-1].second;
    ll mx = 0;
    for(int i = 0 ; i < n; ++i){
        if(c == k-1) break;
        if(i == ind) continue;
        c++;
        mx = max(mx, v[i] + c);
    }
    ans = max(ans, mx + p[n-1].first  +1);

    //222
     c = 0;
     sum = 0;
     ind = p[n-2].second;
     mx = 0;
    for(int i = 0 ; i < n; ++i){
        if(c == k-1) break;
        if(i == ind) continue;
        c++;
        mx = max(mx, v[i] + c);
    }
    ans = max(ans, mx + p[n-2].first  +1);
    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";
    }


}