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

/* ------------ Theorems and Lemmas ------------ */

// Fermat's Little Theorem
// (1) ((a ** p) - a) % p = 0; if 'p' is prime
// (2) Further, if 'a % p != 0' (a and b should be coprime i.e. gcd(a, b) = 1), then ((a ** (p - 1)) - 1) % p = 0

/* -------------- End of theorems -------------- */

public class Solution {

	protected static final String[] FACTS = new String[] { "", "", "2", "3", "322", "5", "53", "7", "7222", "7332" };
	protected static final Random RANDOM = new Random();

	// private static long[] dp = new long[100001];
	// private static final int MOD = (int) 1e9 + 7;

	public static void main(String[] args) {
		// long start = System.nanoTime();
		FastReader reader = new FastReader();
		int t = 1;
		t = reader.nextInt();
		StringBuilder ans = new StringBuilder("");
		while (t-- > 0) {
			int n = reader.nextInt();
			int[] a = reader.readArray(n);
			long sum = 0;
			for (int i = 0; i < n; ++i) {
				int max = a[i];
				int j = i;
				while (j < n && sign(a[j]) == sign(a[i]))
					max = Math.max(max, a[j++]);
				sum += max;
				i = j - 1;
			}
			ans.append(sum + "\n");
		}
		reader.close();
		System.out.println(ans.toString().trim());
		// long end = System.nanoTime();
		// System.out.format("Exec time: %.2f seconds.%n", (end - start) / 1e9);
	}

	private static int sign(int n) {
		return n < 0 ? -1 : 1;
	}

	public static int upperBound(int[] array, int val) {
		int low = 0;
		int high = array.length;
		while (low < high) {
			int mid = low + ((high - low) >> 1);
			if (array[mid] > val)
				high = mid;
			else
				low = mid + 1;
		}
		return low;
	}

	public static int lowerBound(int[] array, int val) {
		int low = 0;
		int high = array.length;
		while (low < high) {
			int mid = low + ((high - low) >> 1);
			if (array[mid] < val)
				low = mid + 1;
			else
				high = mid;
		}
		return low;
	}

	public static void ruffleSort(int[] array) {
		for (int i = 0; i < array.length; i++) {
			int oi = RANDOM.nextInt(array.length);
			int temp = array[i];
			array[i] = array[oi];
			array[oi] = temp;
		}
		Arrays.sort(array);
	}

	// Prime
	public static boolean prime(int n) {
		if (n < 2)
			return false;
		for (int i = 2; i * i <= n; ++i)
			if (n % i == 0)
				return false;
		return true;
	}

	// Binary Exponentiation
	public static long binPow(long a, long n, long mod) {
		// Iterative approach
		a %= mod;
		long result = 1;
		while (n > 0l) {
			if ((n & 1l) != 0l)
				result = result * a % mod;
			a = a * a % mod;
			n >>= 1l;
		}
		return result;

		// Recursive approach
		/*
		 * if (n == 0l) return 1l; long res = binpow(a, n / 2, mod); if ((n & 1l) != 0l)
		 * return ((res % mod) * (res % mod) * (a % mod)) % mod; else return ((res %
		 * mod) * (res % mod)) % mod;
		 */
	}

	// Division under modulo
	public static long modInv(long x, long mod) {
		return binPow(x, mod - 2l, mod);
	}

	// GCD
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	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().trim());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		float nextFloat() {
			return Float.parseFloat(next());
		}

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

		int[] readArray(int size) {
			int[] ar = new int[size];
			for (int i = 0; i < size; ++i)
				ar[i] = nextInt();
			return ar;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}