

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

import static java.lang.Math.*;

public class Contest {
    public static class pair implements Comparable<pair> {
        int u;
        long val;

        public pair(int a, long value) {
            u = a;
            val = value;
        }

        @Override
        public int compareTo(pair p) {
            return Long.compare(val, p.val);
        }
    }

    static int n;
    static ArrayList<pair>[] adj;
    static long dist[];
    static int parent[];
    static long inf = (long) 1e16;

    public static long dijecstra(int start, int end) {
        dist = new long[n];
        parent = new int[n];
        Arrays.fill(dist, inf);
        PriorityQueue<pair> pq = new PriorityQueue<>();
        pq.add(new pair(start, 0));
        while (!pq.isEmpty()) {
            pair cur = pq.poll();
            int u = cur.u;
            long val = cur.val;
            if (val > dist[u])
                continue;
            if (u == end)
                return val;
            dist[u] = val;
            for (pair p : adj[u])
                if (p.val + val < dist[p.u]) {
                    pq.add(new pair(p.u, dist[p.u] = p.val + val));
                    parent[p.u] = u;
                }
        }
        return -1;
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            long ans = 0;
            int[] Arr = new int[n];
            int sofar = sc.nextInt();
            Arr[0] = sofar;
            for (int i = 1; i < n; i++) {
                Arr[i] = sc.nextInt();
                if (Arr[i] * 1l * Arr[i - 1] < 0) {
                    ans += sofar;
                    sofar=Arr[i];
                }
                else  sofar = max(sofar, Arr[i]);


            }
            ans += sofar;

            pw.println(ans);
        }
        pw.close();

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException, IOException {
            return br.ready();
        }

    }
}
