#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, pre, ans, i, j, maxi, maxn, js, len, maxilen, a[1000];
  int t, n;
  int q, p, flag1, flag2;
  scanf("%d", &t);
  while (t--) {
    maxi = 0;
    pre = 0;
    p = q = 5;
    flag1 = flag2 = 1;
    js = 0;
    len = 0;
    maxilen = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%lld", &x);
      if (x > 0)
        p = 1;
      else
        p = 0;
      if (p != q) {
        len++;
        maxi += pre + x;
        flag1 = 0;
      } else {
        flag2 = 0;
        if (len >= maxilen) {
          a[js++] = maxi, maxilen = len, len = 0;
        }
        len = 0, maxi = 0;
      }
      pre = x;
      q = p;
    }
    if (!flag2)
      printf("%lld\n", maxi);
    else if (!flag1) {
      maxn = a[0];
      for (i = 1; i < js; i++)
        if (a[i] > maxn)
          maxn = a[i];
        else
          printf("%lld\n", maxn);
    } else
      printf("-1\n");
  }
  return 0;
}
