#include <bits/stdc++.h>
using namespace std;
int main() {
  auto sgn = [&](int x) {
    if (x > 0)
      return 1;
    else
      return -1;
  };
  int n, x, t, j;
  long long int sum = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      v[i] = x;
    }
    for (int i = 0; i < n; i++) {
      int c = v[i];
      j = i;
      while (j < n && sgn(v[i]) == sgn(v[j])) {
        c = max(c, v[j]);
        j++;
      }
      sum += c;
      i = j - 1;
    }
    printf("%I64d\n", sum);
  }
  return 0;
}
