#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long t, n, x;
long long pre;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    long long sum = 0;
    cin >> pre;
    for (int i = 2; i <= n; ++i) {
      scanf("%lld", &x);
      if (x * pre > 0)
        pre = max(pre, x);
      else
        sum += pre, pre = x;
    }
    sum += pre;
    printf("%lld\n", sum);
  }
  return 0;
}
