#include <bits/stdc++.h>
using namespace std;
bool sign(long long int n) { return n > 0; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, i;
    cin >> n;
    long long int a[n], ans = 0, mx, j;
    for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
    for (long long int i = 0; i <= n - 1; i++) {
      mx = a[i];
      j = i;
      while (j < n && sign(a[i]) == sign(a[j])) {
        mx = max(mx, a[j]);
        j++;
      }
      i = j - 1;
      ans += mx;
    }
    cout << ans << endl;
  }
  return 0;
}
