import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class practice_DP {

	static Reader r = new Reader();
	static PrintWriter out = new PrintWriter(System.out);

	private static void solve1() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();
			int m = r.nextInt();

			int x = r.nextInt();
			int y = r.nextInt();

			char ch[][] = new char[n][m];

			long ans = 0;

			for (int i = 0; i < n; i++) {
				ch[i] = r.next().toCharArray();
				for (int j = 0; j < m; j++) {
					if (ch[i][j] == '.') {
						if (j + 1 < m && ch[i][j + 1] == '.') {
							if (2 * x < y) {
								ans += 2 * x;
							} else {
								ans += y;
							}
							j++;
						} else {
							ans += x;
						}
					}
				}
			}

			res.append(ans).append("\n");

		}

		out.print(res);
		out.close();
	}

	private static void solve2() throws IOException {

		StringBuilder res = new StringBuilder();

		int n = r.nextInt();
		int k = r.nextInt();

		int arr[] = r.nextIntArray(n);

		int cnt = 0;

		for (int i = 1; i < n; i++) {
			if (arr[i] + arr[i - 1] < k) {
				cnt += k - (arr[i] + arr[i - 1]);
				arr[i] += k - (arr[i] + arr[i - 1]);
			}
		}

		res.append(cnt).append("\n");
		for (int i = 0; i < n; i++) {
			res.append(arr[i] + " ");
		}

		out.print(res);
		out.close();

	}

	private static void solve3() throws IOException {

		int n = r.nextInt();

		int ans = 0;
		if ((n & 1) != 0) {
			ans = 0;
		} else {
			ans = (int) Math.pow(2, n / 2);
		}

		out.print(ans);
		out.close();

	}

	private static void solve4() throws IOException {

		int n = r.nextInt();

		int cnt = 0;

		ArrayList<Integer> ans = new ArrayList<Integer>();

		int start = 1, sum = 0;
		while (true) {
			sum += start;
			if (sum > n) {
				sum -= start;
				break;
			} else {
				ans.add(start++);
			}
		}

//		System.out.println(sum);
//		System.out.println(ans);

		ans.set(ans.size() - 1, ans.get(ans.size() - 1) + (n - sum));
		out.print(ans.size() + "\n");
		for (int candies : ans) {
			out.print(candies + " ");
		}
		out.close();

	}

	private static void solve5() throws IOException {

		int n = r.nextInt();

		int fibo[] = new int[21];
		fibo[0] = fibo[1] = 1;

		for (int i = 2; i <= 20; i++) {
			fibo[i] = (fibo[i - 1] + fibo[i - 2]);
		}

		out.print(fibo[n]);
		out.close();

	}

	private static int binarySearch6(int ele) {
		int lt = 0, rt = arr.length - 1;
		int ans = 0;
		while (lt <= rt) {
			int mid = (lt + rt) / 2;
			if (arr[mid] > ele) {
				rt = mid - 1;
			} else {
				ans = mid + 1;
				lt = mid + 1;
			}
		}
		return ans;
	}

	private static void solve6() throws IOException {

		StringBuilder res = new StringBuilder();

		int n = r.nextInt();
		arr = r.nextIntArray(n);

		Arrays.sort(arr);

		int q = r.nextInt();
		while (q-- > 0) {
			int ele = r.nextInt();
			res.append(binarySearch6(ele)).append("\n");
		}

		out.print(res);
		out.close();

	}

	private static void solve7() throws IOException {

		String s = r.next();

		int dp1[] = new int[s.length() + 1];
		int dp2[] = new int[s.length() + 1];

		dp1[0] = dp2[0] = 0;
		for (int i = 0; i < s.length(); i++) {
			dp1[i + 1] = dp1[i];
			dp2[i + 1] = dp2[i];
			if (s.charAt(i) == '.') {
				if (i + 1 < s.length() && s.charAt(i + 1) == '.') {
					dp1[i + 1]++;
				}
			} else {
				if (i + 1 < s.length() && s.charAt(i + 1) == '#') {
					dp2[i + 1]++;
				}
			}
		}

//		System.out.println(Arrays.toString(dp1));
//		System.out.println(Arrays.toString(dp2));

		int m = r.nextInt();
		while (m-- > 0) {

			int lt = r.nextInt() - 1;
			int rt = r.nextInt() - 1;

			out.print(dp1[rt] - dp1[lt] + dp2[rt] - dp2[lt] + "\n");

		}
		out.close();

	}

	static class Query {
		int pos, val;

		public Query(int idx, int vali) {
			pos = idx;
			val = vali;
		}
	}

	static int cnt = 0, freq[], arr[];

	private static void add(int idx) {
		if (freq[arr[idx]] == 0) {
			cnt++;
		}
		freq[arr[idx]]++;
	}

	private static void remove(int idx) {
		freq[arr[idx]]--;
		if (freq[arr[idx]] == 0) {
			cnt--;
		}
	}

	private static void solve8() throws IOException {

		int n = r.nextInt();
		int m = r.nextInt();

		arr = new int[n + 1];
		freq = new int[(int) 1e5 + 1];
		Query q[] = new Query[m];

		for (int i = 1; i <= n; i++) {
			arr[i] = r.nextInt();
			add(i);
		}

		// Applying MO's Algorithm

		for (int i = 0; i < m; i++) {
			q[i] = new Query(i, r.nextInt());
		}
		Arrays.sort(q, new Comparator<Query>() {
			@Override
			public int compare(Query o1, Query o2) {
				return o1.val - o2.val;
			}
		});

		int ans[] = new int[m];
		int lt = 1;
		for (int i = 0; i < m; i++) {
			int val = q[i].val;
			while (lt < val) {
				remove(lt++);
			}
			ans[q[i].pos] = cnt;
		}

		for (int i = 0; i < m; i++) {
			out.println(ans[i]);
		}
		out.close();

	}

	private static void solve9() throws IOException {

		int n = r.nextInt();
		int k = r.nextInt();

		int dp[] = r.nextIntArray(n);
		for (int i = 1; i < n; i++) {
			dp[i] += dp[i - 1];
		}

		int min = dp[k - 1], ans = 0;

		for (int i = k; i < n; i++) {
			if (dp[i] - dp[i - k] < min) {
				min = dp[i] - dp[i - k];
				ans = i - k + 1;
			}
		}

		out.print(++ans);
		out.close();

	}

	private static long sum(long n) {
		return ((n * (3 * n + 1)) / 2);
	}

	private static long binarySearch10(long n) {
		long lt = 1, rt = n;
		long ans = 0;
		while (lt <= rt) {
			long mid = (lt + rt) / 2;
			long val = sum(mid);
			if (val <= n) {
				ans = mid;
				lt = mid + 1;
			} else {
				rt = mid - 1;
			}
		}
		return ans;
	}

	private static void solve10() throws IOException {

		int t = r.nextInt();

		while (t-- > 0) {

			long n = r.nextLong();

			long cnt = 0;

			while (n > 1) {
				long tallest = binarySearch10(n);
				cnt++;
				n -= sum(tallest);
			}

			out.println(cnt);

		}
		out.close();

	}

	private static void solve11() throws IOException {

		int a1 = r.nextInt();
		int a2 = r.nextInt();

		int temp = a1;
		a1 = Math.min(a1, a2);
		a2 = Math.max(a2, temp);

		int cnt = 0;
		while (a1 > 0 && a2 > 0) {
			if (a1 <= 1 && a2 <= 1) {
				break;
			}
			if (a1 > 2) {
				cnt++;
				a1 -= 2;
				a2++;
			} else {
				cnt++;
				a1++;
				a2 -= 2;
			}
		}

		out.print(cnt);
		out.close();

	}

	private static int digitSum(int num) {
		int sum = 0;
		while (num > 0) {
			sum += (num % 10);
			num /= 10;
		}
		return sum;
	}

	private static void solve12() throws IOException {

		int k = r.nextInt();

		int num = 18;
		while (k > 0) {
			if (digitSum(++num) == 10) {
				k--;
			}
		}

		out.print(num);
		out.close();

	}

	private static void solve13() throws IOException {

		int n = r.nextInt();

		int h[] = new int[n];
		int w[] = new int[n];
		int hi[] = new int[n];
		int w_cumu = 0;

		for (int i = 0; i < n; i++) {
			w[i] = r.nextInt();
			w_cumu += w[i];
			h[i] = r.nextInt();
			hi[i] = h[i];
		}

		Arrays.sort(hi);

		for (int i = 0; i < n; i++) {
			int ans = (w_cumu - w[i]);
			if (hi[n - 1] == h[i]) {
				ans *= hi[n - 2];
			} else {
				ans *= hi[n - 1];
			}
			out.print(ans + " ");
		}
		out.close();

	}

	private static long maxDigit(long num) {
		long max = -1;
		while (num > 0) {
			long digit = num % 10;
			num /= 10;
			max = Math.max(max, digit);
		}
		return max;
	}

	private static void solve14() throws IOException {

		long n = r.nextLong();

		long cnt = 0;
		while (n > 0) {
			n -= maxDigit(n);
			cnt++;
		}

		out.print(cnt);
		out.close();

	}

	private static void solve15() throws IOException {

		int n = r.nextInt();
		int arr[] = r.nextIntArray(n);

		int dp[] = new int[n + 1];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == 0) {
				dp[i + 1] = 1;
			} else {
				tot++;
				dp[i + 1] = -1;
			}
		}

		for (int i = 1; i <= n; i++) {
			dp[i] += dp[i - 1];
		}

		int max = Integer.MIN_VALUE;
		for (int i = n; i >= 1; i--) {
			for (int j = 1; j <= i; j++) {
				if (tot + dp[i] - dp[j - 1] > max) {
					max = tot + dp[i] - dp[j - 1];
				}
			}
		}

		out.print(max);
		out.close();

	}

	private static void solve16() throws IOException {

		int t = r.nextInt();

		while (t-- > 0) {

			int n = r.nextInt();
			int arr[] = new int[n];

			int pos = 0, neg = 0;
			for (int i = 0; i < n; i++) {
				arr[i] = r.nextInt();
				if (arr[i] < 0) {
					neg++;
				} else {
					pos++;
				}
			}

			boolean flag = (neg == 0 || pos == 0) ? false : true;

			long ans = -1;
			if (n == 1) {
				ans = arr[0];
			}

			if (flag) {
				ArrayList<Integer> sub_seq = new ArrayList<Integer>();
				int i = 0;
				while (i < n) {
					int max = Integer.MIN_VALUE;
					while (i < n && arr[i] < 0) {
						max = Math.max(max, arr[i++]);
					}
					if (max != Integer.MIN_VALUE)
						sub_seq.add(max);
					max = Integer.MIN_VALUE;
					while (i < n && arr[i] > 0) {
						max = Math.max(max, arr[i++]);
					}
					if (max != Integer.MIN_VALUE)
						sub_seq.add(max);
				}
				long sum = 0;
				for (int ele : sub_seq) {
					sum += ele;
				}
				ans = sum;
			}

			out.print(ans + "\n");

		}
		out.close();

	}

	private static void solve17() throws IOException {

		out.print(0);
		out.close();

	}

	private static void solve18() throws IOException {

		out.print(0);
		out.close();

	}

	private static void solve19() throws IOException {

		out.print(0);
		out.close();

	}

	private static void solve20() throws IOException {

		out.print(0);
		out.close();

	}

	public static void main(String[] args) throws IOException {

//		solve1();

//		solve2();

//		solve3();

//		solve4();

//		solve5();

//		solve6();

//		solve7();

//		solve8();

//		solve9();

//		solve10();

//		solve11();

//		solve12();

//		solve13();

//		solve14();

//		solve15();

		solve16();

//		solve17();

//		solve18();

//		solve19();

//		solve20();

	}

	static class Reader {

		final private int BUFFER_SIZE = 1 << 12;
		boolean consume = false;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		private boolean reachedEnd = false;

		public Reader() {
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = 0;
			bytesRead = 0;
		}

		public boolean hasNext() {
			return !reachedEnd;
		}

		private void fillBuffer() throws IOException {
			bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1) {
				buffer[0] = -1;
				reachedEnd = true;
			}
		}

		private void consumeSpaces() throws IOException {
			while (read() <= ' ' && reachedEnd == false)
				;
			bufferPointer--;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

		public String next() throws IOException {
			StringBuilder sb = new StringBuilder();
			consumeSpaces();
			byte c = read();
			do {
				sb.append((char) c);
			} while ((c = read()) > ' ');
			if (consume) {
				consumeSpaces();
			}
			;
			if (sb.length() == 0) {
				return null;
			}
			return sb.toString();
		}

		public String nextLine() throws IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			return str;
		}

		public int nextInt() throws IOException {
			consumeSpaces();
			int ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public long nextLong() throws IOException {
			consumeSpaces();
			long ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10L + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			consumeSpaces();
			double ret = 0;
			double div = 1;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public int[][] nextIntMatrix(int n, int m) throws IOException {
			int[][] grid = new int[n][m];
			for (int i = 0; i < n; i++) {
				grid[i] = nextIntArray(m);
			}
			return grid;
		}

		public char[][] nextCharacterMatrix(int n) throws IOException {
			char[][] a = new char[n][];
			for (int i = 0; i < n; i++) {
				a[i] = next().toCharArray();
			}
			return a;
		}

		public void close() throws IOException {
			if (System.in == null) {
				return;
			} else {
				System.in.close();
			}
		}
	}

}