
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

public class New {
    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 sumP=0,sumN=0;
        int posi=-1,negi=-1;int lenN=1;int lenP=1;
        for (int i = 0; i <n ; i++) {
            if (a[i]>0){
                posi=i;
                break;
            }
        }

        for (int i = 0; i <n ; i++) {
            if (a[i]<0){
                negi=i;
                break;
            }
        }
        if (posi!=-1){
            flag=1;pos=a[posi];
            for (int i = posi+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;
                        sumP+=pos;lenP++;
                        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;
                        sumP+=neg;lenP++;
                        neg=-1000000000;
                        //System.out.println("4 "+neg+" "+flag+" "+sum+" a="+a[i]+" "+i);
                    }
                }
                if (i==n-1&&flag==1){
                    sumP+=pos;
                }else if (i==n-1&&flag==-1){
                    sumP+=neg;
                }
            }
            if (n==1)sumN=a[0];
        }
        pos=0;
        if (negi!=-1){

            //System.out.println("neg "+negi+" "+pos);
            flag=-1;neg=a[negi];
            for (int i = negi+1; i <n ; i++) {
                //System.out.println("xunhuan"+flag);
                if (flag==-1){
                    //System.out.println("-1 "+i+" "+a[i]);
                    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;
                        sumN+=neg;lenN++;
                        neg=-1000000000;
                        //System.out.println("4 "+neg+" "+flag+" "+sumN+" a="+a[i]+" "+i+" "+lenN);
                    }
                }else if (flag==1){

                    if (a[i]>0&&a[i]>=pos){
                        pos=a[i];
                        //System.out.println("1  "+pos+" "+flag+" "+sumN+" a="+a[i]+" "+i);
                    }else if (a[i]<0&&a[i]>=neg){
                        flag=-1;
                        sumN+=pos;lenN++;
                        pos=0;
                        neg=a[i];
                        //System.out.println("2 "+neg+" "+flag+" "+sumN+" a="+a[i]+" "+i+" "+lenN);
                    }
                }
                if (i==n-1&&flag==1){
                    sumN+=pos;
                }else if (i==n-1&&flag==-1){
                    sumN+=neg;
                }

            }
            if (n==1)sumN=a[0];
        }
        if (lenN>lenP&&sumN!=0){
            System.out.println(sumN);//+" "+lenN+" "+lenP+" 1"
        }else if (lenP>lenN&&sumP!=0){
            System.out.println(sumP);
        }else if (sumP==0){
            System.out.println(sumN);
        }else if (sumN==0){
            System.out.println(sumP);
        }
    }
}
