import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Round636C {

	public static void solve() {
		int t = s.nextInt();
		while(t-- > 0) {
			int n = s.nextInt();
			int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = s.nextInt();
			Pair[][] dp = new Pair[n][2];
			if(arr[0] > 0) {
				dp[0][0] = new Pair(arr[0], 1);
				dp[0][1] = new Pair(0, 0);
			}else {
				dp[0][0] = new Pair(0, 0);
				dp[0][1] = new Pair(arr[0], 1);
			}
			for(int i = 1; i < n; i++) {
				int curr = arr[i];
				if(curr < 0) {
					dp[i][0] = new Pair(dp[i - 1][0].x, dp[i - 1][0].y);
					long sum = dp[i - 1][0].x + curr;
					long len = dp[i - 1][0].y + 1;
					if(len > dp[i - 1][1].y) {
						dp[i][1] = new Pair(sum, len);
					}else if(len == dp[i - 1][1].y) {
						if(sum > dp[i - 1][1].x) {
							dp[i][1] = new Pair(sum, len);
						}else {
							dp[i][1] = new Pair(dp[i - 1][1].x, dp[i - 1][1].y);
						}
					}else {
						dp[i][1] = new Pair(dp[i - 1][1].x, dp[i - 1][1].y);
					}
				}else{
					dp[i][1] = new Pair(dp[i - 1][1].x, dp[i - 1][1].y);
					long sum = dp[i - 1][1].x + curr;
					long len = dp[i - 1][1].y + 1;
					if(len > dp[i - 1][0].y) {
						dp[i][0] = new Pair(sum, len);
					}else if(len == dp[i - 1][0].y) {
						if(sum > dp[i - 1][0].x) {
							dp[i][0]  = new Pair(sum, len);
						}else {
							dp[i][0] = new Pair(dp[i - 1][0].x, dp[i - 1][0].y); 
						}
					}else {
						dp[i][0] = new Pair(dp[i - 1][0].x, dp[i - 1][0].y);
					}
				}
			}
			if(dp[n - 1][0].y > dp[n - 1][1].y) {
				out.println(dp[n - 1][0].x);
			}else if(dp[n - 1][0].y <  dp[n - 1][1].y) {
				out.println(dp[n - 1][1].x);
			}else {
				long ans = Long.max(dp[n - 1][0].x, dp[n - 1][1].x);
				out.println(ans);
			}
		}
	}
	
	public static class Pair implements Comparable<Pair> {
		long x;
		long y;

		public Pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair x) {
			//ascending order
			if (this.x == x.x) {
				return Long.compare(this.y, x.y);
			} else {
				return Long.compare(this.x, x.x);
			}
			//descending order
			//		if(this.x==x.x) {
			//			return Long.compare(x.y, this.y);
			//		}else {
			//			return Long.compare(x.x, this.x);
			//		}
		}

		//Use it rarely because it has about 0.115% collision rate which is quite 
		//and hence it will constantly keep go into equal function and hence slow
		public int hashCode() {
			return Long.hashCode(x) ^ Long.hashCode(y);
		}

		public boolean equals(Object o) {
			if (!(o instanceof Pair)) {
				return false;
			}
			Pair x = (Pair) o;
			if (x.x == this.x && x.y == this.y) {
				return true;
			} else {
				return false;
			}
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	
}
