#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    long long int n, a[200005], pos = 0, neg = -1000000009, sum = 0, i;
    string turn;
    scanf("%lld", &n);
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    for (i = 0; i < n; i++) {
      if (a[i] < 0 && a[i] > neg) {
        neg = a[i];
        sum += pos;
        pos = 0;
        turn = "neg";
      } else if (a[i] > 0 && a[i] > pos) {
        pos = a[i];
        if (neg > -1000000009) {
          sum += neg;
          neg = -1000000009;
          turn = "pos";
        }
      }
    }
    if (pos > 0 && turn == "pos")
      sum += pos;
    else if (neg < 0 && turn == "neg")
      sum += neg;
    if (n == 1) sum = a[0];
    printf("%lld\n", sum);
  }
  return 0;
}
