
import java.util.*;

public class P1343
{
    private final static int MOD = 1_000_000_007;

    public static long mod(long a, long b) {
        return ((a % b) + b ) % b;
    }

    public static int mod (int a, int b) {
        return ((a % b) + b ) % b;
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
	int cases = in.nextInt();
	while (cases-- > 0) {
	    int n = in.nextInt();
	    long sumv = 0, pre = in.nextInt();
	    while (--n > 0) {
		int cur = in.nextInt();
		if ((cur ^ pre) < 0) {
		    sumv += pre;
		    pre = cur;
		}
		else {
		    pre = Math.max(pre, cur);
		}
	    }
	    sumv += pre;
	    System.out.println(sumv);
	}
	in.close();
    }
}
