import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long t=sc.nextLong();
for(int i =0;i<t;i++) {
long n = sc.nextLong();
long k =sc.nextLong();
long book[]=new long[10000];
for(int j=0;j<n;j++)
{
book[i]=sc.nextLong();
}
long result= binarySearch(book,n,k);
System.out.println();
}
}
public static long binarySearch(long books[], long n, long k) {
long ans = 0, s = 0, e = 0;
long sum = 0;
for (int i = 0; i < n; i++) {
sum += books[i];
s = Math.max(s, books[i]);
}
e = sum;
while (s <= e) {
long mid = (s + e) / 2;
if (isValid(books, n, k, mid)) {
ans = mid;
e = mid - 1;
} else {
s = mid + 1;
}
}
return ans;
}
public static boolean isValid(long books[], long n, long k, long ans) {
long students = 1;
long current_page = 0;
for (int i = 0; i < n; i++) {
if(books[i]>ans) {
return false;
}
if (current_page + books[i] > ans) {
current_page = books[i];
students++;
if (students > n) {
return false;
}
} else {
current_page += books[i];
}
}
return true;
}
}