#include <bits/stdc++.h>
using namespace std;
main(){
int t ;
cin >> t ;
while(t--){
long long n , k ;
cin >> k >> n;
vector<long long> arr(n) ;
for(int i = 0; i < n; ++i)cin >> arr[i] ;
long long s = *max_element(arr.begin(), arr.end()), e = (n)**max_element(arr.begin(), arr.end()) ;
for(int i = 1; i <= n - 1; ++i){
arr[i] += arr[i-1] ;
}
while(e > s){
long long mid = s + (e-s) / 2 ;
long long sum = 0 ;
bool fff = false ;
for(int i = 0; i < k; ++i){
auto it = upper_bound(arr.begin(), arr.end(), sum + mid) ;
if(it == arr.end()){
fff = true ;
break ;
}
if(it == arr.begin())break ;
sum -= *(--it) ;
if(sum == 0)break ;
sum = *it ;
}
if(fff)e = mid ;
else s = mid + 1 ;
}
cout << e << "\n" ;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7IAoKbWFpbigpewogICAgaW50IHQgOyAKICAgIGNpbiA+PiB0IDsKICAgIHdoaWxlKHQtLSl7CiAgICBsb25nIGxvbmcgbiAsIGsgOwogICAgY2luID4+IGsgPj4gbjsKICAgIAogICAgdmVjdG9yPGxvbmcgbG9uZz4gYXJyKG4pIDsKICAgIAogICAgZm9yKGludCBpID0gMDsgaSA8IG47ICsraSljaW4gPj4gYXJyW2ldIDsgCgogICAgCiAgICBsb25nIGxvbmcgcyA9ICptYXhfZWxlbWVudChhcnIuYmVnaW4oKSwgYXJyLmVuZCgpKSwgZSA9IChuKSoqbWF4X2VsZW1lbnQoYXJyLmJlZ2luKCksIGFyci5lbmQoKSkgOwogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG4gLSAxOyArK2kpewogICAgICAgIGFycltpXSArPSBhcnJbaS0xXSA7CiAgICB9CiAgICAKICAgIHdoaWxlKGUgPiBzKXsKICAgICAgICBsb25nIGxvbmcgbWlkID0gcyArIChlLXMpIC8gMiA7CiAgICAgICAgCiAgICAgICAgbG9uZyBsb25nIHN1bSA9IDAgOwogICAgICAgIGJvb2wgZmZmID0gZmFsc2UgOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBrOyArK2kpewogICAgICAgICAgICBhdXRvIGl0ID0gdXBwZXJfYm91bmQoYXJyLmJlZ2luKCksIGFyci5lbmQoKSwgc3VtICsgbWlkKSA7CiAgICAgICAgICAgIGlmKGl0ID09IGFyci5lbmQoKSl7CiAgICAgICAgICAgICAgICBmZmYgPSB0cnVlIDsKICAgICAgICAgICAgICAgIGJyZWFrIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihpdCA9PSBhcnIuYmVnaW4oKSlicmVhayA7CiAgICAgICAgICAgIHN1bSAtPSAqKC0taXQpIDsKICAgICAgICAgICAgaWYoc3VtID09IDApYnJlYWsgOwogICAgICAgICAgICBzdW0gPSAqaXQgOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBpZihmZmYpZSA9IG1pZCA7CiAgICAgICAgZWxzZSBzID0gbWlkICsgMSA7CiAgICAgICAgCiAgICB9CiAgICAKICAgIGNvdXQgPDwgZSA8PCAiXG4iIDsKICAgIH0KICAgIAp9IA==