#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
const long long inf = -1000000007;
long long a[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, i, x, y, ans = 0, maxx = 0;
    scanf("%lld", &n);
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    x = 0, y = 0;
    for (i = 0; i < n; i++) {
      if (a[i] >= 0) {
        if (y == 1) {
          ans += maxx;
          maxx = 0;
          y = 0;
        }
        if (x == 0) {
          x = 1;
          maxx = a[i];
        } else {
          maxx = max(a[i], maxx);
        }
      }
      if (a[i] < 0) {
        if (x == 1) {
          ans += maxx;
          maxx = inf;
          x = 0;
        }
        if (y == 0) {
          maxx = a[i];
          y = 1;
        } else
          maxx = max(maxx, a[i]);
      }
    }
    ans += maxx;
    printf("%lld\n", ans);
  }
}
