#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
int cas, n;
long long a[maxx];
int main() {
  scanf("%d", &cas);
  while (cas--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    long long ans = 0;
    long long maxT = a[1];
    for (int i = 2; i <= n; i++) {
      if (a[i] * a[i - 1] > 0) {
        maxT = max(maxT, a[i]);
      } else {
        ans += maxT;
        maxT = a[i];
      }
    }
    ans += maxT;
    printf("%lld\n", ans);
  }
  return 0;
}
