import java.util.*;
import java.io.*;

public class Main {
    public static void main (String[] args) {
        FastScanner scanner = new FastScanner();
        int t = scanner.nextInt();
            while(t-- > 0) {
                int n = scanner.nextInt();
                int[] a = new int[n];
                int sumArr[] = new int[n];
                int max = Integer.MIN_VALUE, currentIndex = 0;
                for (int i = 0; i < n; i++) {
                    a[i] = scanner.nextInt();
                    if (i > 0 && Math.signum(a[i]) != Math.signum(a[i - 1])) {
                        currentIndex++;
                        max = Integer.MIN_VALUE;
                    }
                    max = Math.max(max, a[i]);
                    sumArr[currentIndex] = max;
                }
                long res = 0;
                for (int val :sumArr){
                    res += val;
                }    
                System.out.println(res);
            }

    }
}


class FastScanner {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public FastScanner() {
        reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    public String nextLine() {
        try {
            return reader.readLine();
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }
}

