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

public class C {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
		int inputs = Integer.parseInt(file.readLine());
		while(inputs-->0) {
			long sum = 0;
			int currMax = 0;
			int n = Integer.parseInt(file.readLine());
			int num;
			StringTokenizer st = new StringTokenizer(file.readLine());
			for(int i = 0; i < n; i++) {
				if(i == 0) {
					currMax = Integer.parseInt(st.nextToken());
				}
				else {
					num = Integer.parseInt(st.nextToken());
					if((currMax ^ num) < 0) {
						sum += currMax;
						currMax = num;
					}
					else {
						currMax = Math.max(currMax, num);
					}
				}
			}
			sum += currMax;
			System.out.println(sum);
		}
		file.close();
	}

}
