#include <bits/stdc++.h>
using namespace std;
bool chksign(long long int n) { return n > 0; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int tc;
  cin >> tc;
  while (tc--) {
    long long int n, mx = 0, sum = 0;
    cin >> n;
    long long int arr[200005];
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n;) {
      int j = i;
      mx = arr[i];
      while (j < n && chksign(arr[i]) == chksign(arr[j]))
        mx = max(arr[j], mx), j++;
      i = j;
      sum += mx;
    }
    cout << sum << "\n";
  }
  return 0;
}
