#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <list>
#include <map>
#include <set>
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FOR(i,a) For(i,1,a)
#define Ford(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,a) Rep(i,0,a)
#define type(x) __typeof(x.begin())
#define foreach(it,x) for(__typeof(x.begin()) it = x.begin() ; it!=x.end() ; it++ )
#define fi first
#define se second
#define dbg(x) cerr<<#x<<":"<<(x)<<endl
#define dg(x) cerr<<#x<<":"<<(x)<<' '
#define fill(x,y) memset(x,y,sizeof x)
#define all(x) x.begin(),x.end()
#define bin(x) (1LL<<(x))
#define gcd __gcd
#define pb push_back
#define NEW(x,n) (x*)calloc(n,sizeof(x))
#define mp make_pair
using namespace std;
typedef long long Lint;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf = 1e9+5143;
const Lint Linf = 1e18+5413;
template<class T> inline void umax(T &a,T b){if(a<b) a = b ; }
template<class T> inline void umin(T &a,T b){if(a>b) a = b ; }
template<class T> inline T abs(T a){return a>0 ? a : -a;}
template<class T> inline T lcm(T a,T b){
return a/gcd(a,b)*b;
}
inline int read(){
int res = 0 ;int neg ;
while(true){char ch = getchar();if(ch>='0' && ch<='9' || ch=='-'){if(ch=='-') neg = -1;else neg = 1 , res = ch-'0';break;} }
while(true){char ch = getchar();if(ch>='0' && ch<='9') res*=10 , res+=ch-'0';else break;}
return res*neg;
}
const int MAXN = 15010;
int N;
int K;
int sum[MAXN];
vi vals;
int pos[MAXN];
ii F[MAXN];
inline void update(ii &a,const ii &b){
umax(a.fi,b.fi);
umin(a.se,b.se);
}
void init(){
REP(i,MAXN) F[i] =ii(-inf,inf);
}
void put(int x,ii val){
x = (N+1) -x + 1 ;
while(x<MAXN){
update(F[x],val);
x+=x&-x;
}
}
ii get(int x){
int i = lower_bound(all(vals),x)-vals.begin()+1;
i = (N+1) - i + 1 ;
ii res = ii(-inf,inf);
while(i>0){
update(res,F[i]);
i-=i&-i;
}
return res;
}
bool can(int m){
init();
ii f ;
put(pos[0],ii(0,0));
FOR(i,N){
f = get(sum[i]-m);
++f.fi;
++f.se;
put(pos[i],f);
}
return f.se<=K && K<=f.fi;
}
void doit(){
N = read();
K = read();
FOR(i,N) sum[i] = sum[i-1] + read();
vii vec;
vals.clear();
vec.pb(ii(0,0));
vals.pb(0);
FOR(i,N){
vals.pb(sum[i]);
vec.pb(ii(sum[i],i));
}
sort(all(vec));
sort(all(vals));
REP(i,vec.size()){
pos[vec[i].se] = i+1;
}
int l = -inf , r = inf ;
while(l+1<r){
int m = (l+r)>>1;
if(can(m)) r = m ;
else l = m ;
}
printf("%d\n",r);
}
int main(){
int t=read();
while(t--){
doit();
}
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KCiNkZWZpbmUgRm9yKGksYSxiKSBmb3IoaW50IChpKT0oYSk7KGkpPD0oYik7KGkpKyspCiNkZWZpbmUgRk9SKGksYSkgRm9yKGksMSxhKQojZGVmaW5lIEZvcmQoaSxhLGIpIGZvcihpbnQgKGkpPShhKTsoaSk+PShiKTsoaSktLSkKI2RlZmluZSBSZXAoaSxhLGIpIGZvcihpbnQgKGkpPShhKTsoaSk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wogICAgaWkgcmVzID0gaWkoLWluZixpbmYpOwogICAgd2hpbGUoaT4wKXsKICAgICAgICB1cGRhdGUocmVzLEZbaV0pOwogICAgICAgIGktPWkmLWk7CiAgICB9CiAgICByZXR1cm4gcmVzOwp9Cgpib29sIGNhbihpbnQgbSl7CiAgICBpbml0KCk7CiAgICBpaSBmIDsKICAgIHB1dChwb3NbMF0saWkoMCwwKSk7CiAgICBGT1IoaSxOKXsKICAgICAgICBmID0gZ2V0KHN1bVtpXS1tKTsKICAgICAgICArK2YuZmk7CiAgICAgICAgKytmLnNlOwogICAgICAgIHB1dChwb3NbaV0sZik7CiAgICB9CiAgICByZXR1cm4gZi5zZTw9SyAmJiBLPD1mLmZpOwp9Cgp2b2lkIGRvaXQoKXsKCiAgICBOID0gcmVhZCgpOwogICAgSyA9IHJlYWQoKTsKCiAgICBGT1IoaSxOKSBzdW1baV0gPSBzdW1baS0xXSArIHJlYWQoKTsKCiAgICB2aWkgdmVjOwogICAgdmFscy5jbGVhcigpOwogICAgdmVjLnBiKGlpKDAsMCkpOwogICAgdmFscy5wYigwKTsKICAgIEZPUihpLE4pewogICAgICAgIHZhbHMucGIoc3VtW2ldKTsKICAgICAgICB2ZWMucGIoaWkoc3VtW2ldLGkpKTsKICAgIH0KICAgIHNvcnQoYWxsKHZlYykpOwogICAgc29ydChhbGwodmFscykpOwogICAgUkVQKGksdmVjLnNpemUoKSl7CiAgICAgICAgcG9zW3ZlY1tpXS5zZV0gPSBpKzE7CiAgICB9CiAKIAogICAgaW50IGwgPSAtaW5mICwgciA9IGluZiA7CiAgICB3aGlsZShsKzE8cil7CiAgICAgICAgaW50IG0gPSAobCtyKT4+MTsKICAgICAgICBpZihjYW4obSkpIHIgPSBtIDsKICAgICAgICBlbHNlICBsID0gbSA7CiAgICB9CgogICAgcHJpbnRmKCIlZFxuIixyKTsKCn0KCmludCBtYWluKCl7CgogICAgaW50IHQ9cmVhZCgpOwogICAgd2hpbGUodC0tKXsKICAgICAgICBkb2l0KCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCgoKCgoK