#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long ans, maxn;
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    scanf("%d", &n);
    scanf("%lld", &a[1]);
    if (n == 1) {
      printf("%lld\n", a[1]);
      continue;
    }
    maxn = a[1];
    ans = 0;
    for (int i = 2; i <= n; ++i) {
      scanf("%lld", &a[i]);
      if ((a[i] > 0 && a[i - 1] > 0) || (a[i] < 0 && a[i - 1] < 0)) {
        maxn = max(a[i], a[i - 1]);
      } else {
        ans += maxn;
        maxn = a[i];
      }
    }
    ans += maxn;
    printf("%lld\n", ans);
  }
}
