#include <bits/stdc++.h>
const int maxn = 1e6 + 7;
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = 3.1415926535897932384626433832795;
long long n, t, a[maxn], ans, maxx;
int main(void) {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld", &n);
    ans = 0;
    for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
    maxx = a[1];
    a[n + 1] = 0;
    long long flag = 0;
    for (long long i = 1; i <= n; i++) {
      maxx = max(maxx, a[i]);
      if ((a[i] > 0 && a[i + 1] <= 0) || (a[i] < 0 && a[i + 1] >= 0)) {
        ans += maxx;
        maxx = a[i + 1];
        flag = 1;
      }
    }
    if (flag == 0) ans += maxx;
    printf("%lld\n", ans);
  }
  return 0;
}
