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

public class  BufferReader{
     static int dp[];
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;


        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        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;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();

        int t=sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int arr[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                arr[i] = sc.nextInt();
            }
            int max;
            long ans = 0;
            int i = 0;
            while (i<=n){
                 max=0;
                while (i<=n && arr[i]>0 ){
                    max=Math.max(arr[i],max);
                    i++;
                }
                ans+=max;
                i++;

            }
            i = 0;
            while (i <= n) {
                max = Integer.MIN_VALUE;
                while (i <= n && arr[i] < 0) {
                    max = Math.max(arr[i], max);
                    i++;
                }
                if ( max != Integer.MIN_VALUE ) {
                    ans += max;
                }
                i++;
            }
            System.out.println(ans);

        }
    }
}
/*

 */