import java.util.*;
public class Main {
public static int kadane_algo(int[] arr) {
int max_current = arr[0];
int max_global = arr[0];
for (int i = 1; i < arr.length; i++) {
if (max_current + arr[i] > arr[i]) {
max_current+=arr[i];
} else {
max_current = arr[i];
}
if (max_current > max_global) {
max_global = max_current;
}
}
return max_global;
}
public static int min(int[] arr) {
int min = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[min] > arr[i]) {
min = i;
}
}
return arr[min];
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
if (1 <= T && 100 >= T) {
for (int i = 0; i < T; i++) {
int N = sc.nextInt();
if (1 <= N && 1000 >= N) {
int[] arr = new int[N];
for (int j = 0; j < arr.length; j++) {
arr[j] = sc.nextInt();
}
int max = kadane_algo(arr);
int min = min(arr);
int sum = 0;
for (int j = 0; j < arr.length; j++) {
sum += arr[j];
}
if (sum < min) {
System.out.println(max);
} else {
if ((sum - min) > max) {
System.out.println((sum - min));
} else {
System.out.println(max);
}
}
}
}
}
sc.close();
}
}