#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 1e9 + 7;
int32_t main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> arr(n);
    for (long long i = 0; i < n; i++) cin >> arr[i];
    if (arr[n - 1] > 0)
      arr.push_back(-1);
    else
      arr.push_back(1);
    long long ans = 0;
    long long curr = arr[0];
    for (long long i = 1; i <= n; i++) {
      if (arr[i] * arr[i - 1] > 0) {
        curr = max(curr, arr[i]);
      } else {
        ans += curr;
        curr = arr[i];
      }
    }
    cout << ans << endl;
  }
}
