import java.util.*;
public class cf1343c {
public static void main(String args[])
{Scanner sc=new Scanner(System.in);
int k=sc.nextInt();
for(int j=1;j<=k;j++)
{int n=sc.nextInt();
int arr[]=new int[n];
arr[0]=sc.nextInt();
int max=arr[0];
int sum=0,g=0;
if(arr[0]>0)
g=1;int f=0;
for(int i=1;i<n;i++)
{arr[i]=sc.nextInt();
if(arr[i]>0)
f=1;
else
f=0;
if(f==g)
{if(arr[i]>max)
max=arr[i];}
else
{sum=sum+max;
max=arr[i];
g=f;}}
sum=sum+max;
System.out.println(sum);
}sc.close();}}