import java.io.*;
import java.util.*;

public class Solutions {
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    while(t-- > 0) {
      int n = sc.nextInt();
      int[] a = new int[n];
      for(int i = 0; i < n; i++) {
        a[i] = sc.nextInt();
      }
      int ans = 0, pr = a[0], mx = a[0];
      for(int i = 1; i < n; i++) {
        if(pr * a[i] < 0) {
          ans += mx;
          pr = a[i];
          mx = a[i];
        } else {
          mx = Math.max(mx, a[i]);
        }
      }
      ans += mx;
      System.out.println(ans);
    }
  }
}