#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 kd[MAXN*5];
int n = MAXN;
inline void merge(ii &g,const ii &l,const ii &r){
g.fi = max(l.fi,r.fi);
g.se = min(l.se,r.se);
}
void init(){
REP(i,MAXN*5) kd[i] = ii(-inf,inf);
}
void modify(int x,ii val,int k=1,int b=1,int e=n){
if(b>x || e<x) return ;
if(b==e){
kd[k] = val;
return ;
}
modify(x,val,k*2,b,(b+e)/2);
modify(x,val,k*2+1,(b+e)/2+1,e);
merge(kd[k],kd[k+k],kd[k+k+1]);
}
ii get(int x1,int x2,int k=1,int b=1,int e=n){
if(b>x2 || e<x1) return ii(-inf,inf);
if(b>=x1 && e<=x2) return kd[k];
ii res ; merge(res,get(x1,x2,k*2,b,(b+e)/2),get(x1,x2,k*2+1,(b+e)/2+1,e));
return res;
}
ii get(int x){
int i = lower_bound(all(vals),x) - vals.begin()+1;
return get(i,n);
}
bool can(int m){
init();
ii f ;
modify(pos[0],ii(0,0));
FOR(i,N){
f = get(sum[i]-m);
++f.fi;
++f.se;
modify(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();
// here is compressing
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;
}
// binary search
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+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KCiNk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E4pIHN1bVtpXSA9IHN1bVtpLTFdICsgcmVhZCgpOwoKICAgIC8vIGhlcmUgaXMgY29tcHJlc3NpbmcKICAgIHZpaSB2ZWM7CiAgICB2YWxzLmNsZWFyKCk7CiAgICB2ZWMucGIoaWkoMCwwKSk7CiAgICB2YWxzLnBiKDApOwogICAgRk9SKGksTil7CiAgICAgICAgdmFscy5wYihzdW1baV0pOwogICAgICAgIHZlYy5wYihpaShzdW1baV0saSkpOwogICAgfQogICAgc29ydChhbGwodmVjKSk7CiAgICBzb3J0KGFsbCh2YWxzKSk7CiAgICBSRVAoaSx2ZWMuc2l6ZSgpKXsKICAgICAgICBwb3NbdmVjW2ldLnNlXSA9IGkrMTsKICAgIH0KICAgIAogICAgLy8gYmluYXJ5IHNlYXJjaAogICAgaW50IGwgPSAtaW5mICwgciA9IGluZiA7CiAgICB3aGlsZShsKzE8cil7CiAgICAgICAgaW50IG0gPSAobCtyKT4+MTsKICAgICAgICBpZihjYW4obSkpIHIgPSBtIDsKICAgICAgICBlbHNlICBsID0gbSA7CiAgICB9CgogICAgcHJpbnRmKCIlZFxuIixyKTsKCn0KCmludCBtYWluKCl7CgogICAgaW50IHQ9cmVhZCgpOwogICAgd2hpbGUodC0tKXsKICAgICAgICBkb2l0KCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCgoKCgoK