#include <iostream>
#include <cstdint>
#include <random>
#include <numeric>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr int maxn = 3e5 + 10;
constexpr ll inf = 1e18;

int n, k;
int vals[maxn];
vector<int> arrs[maxn];
int ans = 0;

void rec_sol(int level) {
    if (level == n) {
        for (int i = 0; i < k; ++i) if (arrs[i].empty()) return;
        int cans = 0;
        for (int i = 0; i < k; ++i) {
            int cv = 0;
            for (int j = 0; j < arrs[i].size(); ++j) cv = max(cv, arrs[i][j] + j + 1);
            cans += cv;
        }
        ans = max(ans, cans);
        return;
    }
    for (int i = 0; i < k; ++i) {
        arrs[i].push_back(vals[level]);
        rec_sol(level + 1);
        arrs[i].pop_back();
    }
}

void solve() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) cin >> vals[i];
    ans = 0;
    rec_sol(0);
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t = 1;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> t;
#else
#ifdef TEST
    freopen("input.txt", "r", stdin);
#else
#endif
#endif
    while (t--) solve();
    return 0;
}
