#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long temp, e = 0, f = 0;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long k, sum = 0;
    for (long long i = 0; i < n; i++) {
      k = a[i];
      while (a[i] * a[i + 1] > 0 && i < n - 1) {
        k = max(k, a[i + 1]);
        i++;
      }
      sum += k;
    }
    cout << sum << endl;
  }
  return 0;
}
