#include <bits/stdc++.h>
int main() {
  int t, n, i;
  long long int a[200005], p, r, ans;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    p = 1;
    if (a[0] < 0) p = -1;
    ans = 0;
    r = a[0];
    for (i = 0; i < n; i++) {
      if (a[i] * p > 0) {
        if (r < a[i]) r = a[i];
      } else {
        ans += r;
        p *= -1;
        r = a[i];
      }
    }
    ans += r;
    printf("%lld\n", ans);
  }
  return 0;
}
