#include <bits/stdc++.h>
using namespace std;
int32_t 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 arr[n];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long sign = 1, idx = 0;
    long long sm = 0, vl = arr[0];
    if (arr[0] < 0) sign = -1;
    while (idx < n) {
      sign = arr[idx] / abs(arr[idx]);
      vl = arr[idx];
      while (idx < n && sign == arr[idx] / abs(arr[idx])) {
        vl = max(vl, arr[idx]);
        idx++;
      }
      sm = sm + vl;
    }
    cout << sm << "\n";
  }
  return 0;
}
