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


public class Main {

    private static boolean isSame(int a, int b) {
        return (a < 0 && b < 0) || (a > 0 && b > 0);
    }

    private static void solve(MyScanner in, PrintWriter out) {
        int n = in.nextInt();
        Queue<Integer> queue = new LinkedList<>();

        for (int i=0;i<n;i++) {
            int x = in.nextInt();
            queue.add(x);
        }

        int cur = queue.poll();
        int prev = cur;

        long ans = 0;

        while (!queue.isEmpty()) {
            cur = queue.poll();

            if (isSame(cur, prev)) {
                prev = Math.max(cur, prev);
            } else {
                ans += prev;
                prev = cur;
            }
        }

        ans += prev;

        out.println(ans);
    }

    public static void main(String[] args) throws FileNotFoundException {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        for (int i=0;i<t;i++) {
            solve(sc, out);
        }
        out.close();
    }


    public static PrintWriter out;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public MyScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}