import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Learning {

    public static void main(String[] args) throws Exception {
        FastInput in = new FastInput();
        StringBuilder st = new StringBuilder();
        int t = in.nextInt();
        while (t-- > 0) {
            int n = in.nextInt();
            int arr[] = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            List<Integer> pos = new ArrayList<>();
            List<Integer> neg = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                if (arr[i] > 0) pos.add(i);
                else neg.add(i);
            }
            int k = pos.size();
            int curr = -1;
            pos.add(n);
            long sum = 0;
            int posN = 0;
            for (int ind : pos) {
                if (ind - curr > 1) {
                    sum += posN;
                    int val = getMax(arr, curr, ind);
                    sum += val;
                    posN = 0;
                }
                if(ind!=n)
                posN = Math.max(arr[ind], posN);
                curr = ind;
            }
            if(arr[n-1]>0){
                sum+=posN;
            }
            st.append(sum).append("\n");

        }
       System.out.println(st.toString());
    }

    private static int getMax(int[] arr, int curr, int ind) {
        int max = Integer.MIN_VALUE;
        for(int i = curr+1;i<ind;i++){
            max = Math.max(arr[i],max);
        }
        return max;
    }

    private static String rev(String substring) {
        StringBuilder str = new StringBuilder(substring);
        String rev = str.reverse().toString();
        return rev;
    }

}

class Pair {
    int a, b;

    Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

class FastInput {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;

    String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    Long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}
