import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
public class AlternatingSub{
	public static void main(String[] args)throws IOException{
		FastReader sc = new FastReader();
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out),"ASCII"),512);
		int t = sc.nextInt();
		while(t-- > 0){
			int n = sc.nextInt();
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			int ml = 1;
			long ms = a[0];
			int index = 0;
			for(int i=1;i<n;i++){
				if(a[i]*a[index] < 0){
					ms += a[i];
					index = i;
				}
				else{
					if(a[i]>a[index]){
						ms = ms - a[index] + a[i];
						index = i;
					}
				}
			}
			out.write(ms + "");
			out.write('\n');
			out.flush();
		}
	}
}
class FastReader{
	BufferedReader br;
	StringTokenizer st;
	public FastReader(){
		br = new BufferedReader(new InputStreamReader(System.in));
	}
	String next(){ 
		while (st == null || !st.hasMoreElements()){ 
			try{ 
				st = new StringTokenizer(br.readLine()); 
			} 
			catch (IOException  e){ 
				e.printStackTrace(); 
			} 
		} 
		return st.nextToken(); 
	}
	int nextInt(){ 
        return Integer.parseInt(next()); 
	}
    long nextLong(){ 
        return Long.parseLong(next()); 
    }
    double nextDouble(){ 
        return Double.parseDouble(next()); 
    }
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
		catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    }
}