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

public class ProblemC {
  private static BufferedReader reader;
  private static PrintWriter writer;
  private static StringTokenizer tokenizer;

  private static String next() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }

  private static int nextInt() throws IOException, NumberFormatException {
    return Integer.parseInt(next());
  }

  private static boolean sameSign(long a, long b) {
    if ((a > 0 && b > 0) || (a < 0 && b < 0))
      return true;
    else
      return false;
  }

  public static void main(String[] args) throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
    writer = new PrintWriter(System.out);

    int t = nextInt();
    for (int i = 0; i < t; ++i) {
      int n = nextInt();
      ArrayList<Long> seq = new ArrayList<>();
      for (int j = 0; j < n; ++j) {
        seq.add((long) nextInt());
      }

      long ans = 0;
      int j = 0;

      while (j < n) {
        long currentMax = seq.get(j);
        while (j + 1 < n && sameSign(seq.get(j), seq.get(j + 1))) {
          currentMax = Math.max(seq.get(j), seq.get(j + 1));
          j++;
        }
        ans += currentMax;
        j++;
      }

      writer.println(ans);
    }

    reader.close();
    writer.close();
  }
}