#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long A[n];
    for (long long i = 0; i < n; i++) cin >> A[i];
    long long now = A[0];
    long long sum = 0;
    bool posi = (now >= 0);
    for (long long i = 1; i < n; i++) {
      if ((posi && A[i] >= 0) || (!posi && !(A[i] >= 0))) {
        now = max(now, A[i]);
      } else {
        sum += now;
        posi = posi ^ 1;
        now = A[i];
      }
    }
    sum += now;
    cout << sum << "\n";
  }
}
