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

public class Subsequence {
        public static void main(String[] args) throws IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter out = new PrintWriter(System.out);
            StringBuilder sb = new StringBuilder("");
            int t = Integer.parseInt(br.readLine());
            while(t-->0){
                String[] in = br.readLine().split(" ");
                int n = Integer.parseInt(in[0]);
                long sum = 0L;
                in = br.readLine().split(" ");
                for(int i=0; i<n;){
                    long a = Long.parseLong(in[i]);
                    int j=i+1;
                    for(;j<n;j++){
                        long b = Long.parseLong(in[j]);
                        if(b>0 && a>0){
                            a=Math.max(a,b);
                        } else if(b<0 && a<0){
                            a=Math.max(a,b);
                        } else {
                            break;
                        }
                    }
                    sum+=a;
                    i=j;
                }
                sb.append(sum+"\n");
            }
            out.print(sb);
            out.flush();
            br.close();
        }
    }

