

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String test_numS=bf.readLine();
        int test_num=Integer.parseInt(test_numS);
        while(test_num>0){
            String N = bf.readLine();
            int n = Integer.parseInt(N);
            String arrS=bf.readLine();
            String arr[]=arrS.split(" ");
            int array[]=new int[n];
            for (int i = 0; i <n ; i++) {
                array[i]=Integer.parseInt(arr[i]);
            }
            solve(array,n);
            test_num--;
        }

    }
    public static void solve(int a[],int n){
        int neg=-1000000000,pos=0;
        int flag=1;
        long sum=0;
        if (a[0]>0){
            flag=1;pos=a[0];
            for (int i = 1; i <n ; i++) {
                if (flag==1){
                    if (a[i]>0&&a[i]>pos){
                        pos=a[i];
                        //System.out.println("1  "+pos+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }else if (a[i]<0&&a[i]>=neg){
                        flag=-1;
                        sum+=pos;
                        pos=0;
                        neg=a[i];
                        //System.out.println("2 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }
                }else if (flag==-1){
                    if (a[i]<0&&a[i]>=neg){
                        neg=a[i];
                        //System.out.println("3 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }else if (a[i]>0&&a[i]>pos){
                        pos=a[i];
                        flag=1;
                        sum+=neg;
                        neg=-1000000000;
                        //System.out.println("4 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }
                }
                if (i==n-1&&flag==1){
                    sum+=pos;
                }else if (i==n-1&&flag==-1){
                    sum+=neg;
                }
            }
        }else if (a[0]<0){
            flag=-1;neg=a[0];
            for (int i = 1; i <n ; i++) {
                if (flag==-1){
                    if (a[i]<0&&a[i]>=neg){
                        neg=a[i];
                        //System.out.println("2 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }else if (a[i]>0&&a[i]>pos){
                        pos=a[i];
                        flag=1;
                        sum+=neg;
                        neg=-1000000000;
                        //System.out.println("4 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }
                }else if (flag==1){
                    if (a[i]>0&&a[i]>pos){
                        pos=a[i];
                        //System.out.println("1  "+pos+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }else if (a[i]<0&&a[i]>=neg){
                        flag=-1;
                        sum+=pos;
                        pos=0;
                        neg=a[i];
                        //System.out.println("2 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }
                }
                if (i==n-1&&flag==1){
                    sum+=pos;
                }else if (i==n-1&&flag==-1){
                    sum+=neg;
                }
            }
        }
        System.out.println(sum);
    }
}

