#include <bits/stdc++.h>
long long a[200011], mm;
bool pos;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    long long ans = 0;
    mm = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%d", a + i);
      if (mm == 0)
        mm = a[i];
      else {
        if (mm * a[i] > 0)
          mm = (mm > a[i] ? mm : a[i]);
        else
          ans += mm, mm = a[i];
      }
    }
    ans += mm;
    printf("%lld\n", ans);
  }
  return 0;
}
