#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  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];
    bool pos = (a[0] > 0);
    long long maxi = a[0], sum = 0;
    for (long long i = 1; i < n; i++) {
      bool b = (a[i] > 0);
      if (b != pos) {
        sum += maxi;
        maxi = a[i];
      } else {
        maxi = max(maxi, a[i]);
      }
      pos = b;
    }
    sum += maxi;
    cout << sum << '\n';
  }
}
