
import java.util.*;
public class Uyi{
    public static Scanner s = new Scanner(System.in);
    public static void main(String[] args) {
        int t = s.nextInt();
        for (int fvvm = 0; fvvm < t; fvvm++) {
            int n = s.nextInt();
            int [] a = new int [n];
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
            }
            int nowmaxx = a[0];
            ArrayList<Integer> al = new ArrayList<>();
            for (int i = 1; i < n; i++) {
                int k = a[i];
                if (Math.signum(k) != Math.signum(nowmaxx)){
                    al.add(nowmaxx);
                    nowmaxx = k;
                }
                else{
                    if (k > nowmaxx) nowmaxx = k;
                }
            }
            al.add(nowmaxx);
            long dt = 0;
            for (int x : al) {
                dt += x;
            }
            System.out.println(dt);

        }
    }
    boolean ispower(int n){
        while (n > 1){
            if (n % 2 == 1) return false;
            n /= 2;
        }
        return true;
    }
}
class Pair1{
    int x; int y;
    Pair1(int x, int y){
        this.x = x;
        this.y = y;
    }
}