import java.util.Scanner;
class MaxSumSubArray {
public static void main
(String[] args
) {
Scanner sc
= new Scanner
(System.
in); int numOfTestCase = sc.nextInt();
for (int i=0;i<numOfTestCase;i++) {
int arrSize = sc.nextInt();
int arr[] = new int[arrSize];
for (int j=0;j<arrSize;j++) {
arr[j] = sc.nextInt();
}
System.
out.
print(findMaxContSubArray
(arr
) + " "); System.
out.
println(maxsumNonContiguous
(arr
)); }
sc.close();
}
public static int findMaxContSubArray(int[] arr){
if (checkAllNegative(arr)) {
int max = findMax(arr);
return max;
}
int max_so_far = 0, max_ending_here = 0;
for (int i = 0; i < arr.length; i++)
{
max_ending_here = max_ending_here + arr[i];
if (max_ending_here < 0)
max_ending_here = 0;
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
return max_so_far;
}
public static int maxsumNonContiguous(int[] arr){
if(arr == null)
return 0;
if (checkAllNegative(arr)) {
int max = findMax(arr);
return max;
}
int arrayLength = arr.length;
int sum1 = arr[0];
int sum2 = 0;
int sum3 =0;
for(int i = 1; i < arrayLength; i++){
sum3
= Math.
max(sum1,sum2
); sum2 = sum3;
sum1 = sum2 + arr[i];
}
return Math.
max(sum1, sum2
); }
public static boolean checkAllNegative(int arr[]) {
for (int i=0;i<arr.length;i++) {
if (arr[i] >= 0)
return false;
}
return true;
}
public static int findMax(int arr[]) {
for (int i=0;i<arr.length;i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKY2xhc3MgTWF4U3VtU3ViQXJyYXkgewoKcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoJCQoJCVNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJCWludCBudW1PZlRlc3RDYXNlID0gc2MubmV4dEludCgpOwoJCQoJCWZvciAoaW50IGk9MDtpPG51bU9mVGVzdENhc2U7aSsrKSB7CgkJCWludCBhcnJTaXplID0gc2MubmV4dEludC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