#include <bits/stdc++.h>
using namespace std;
bool oppositeSigns(int x, int y) { return ((x ^ y) < 0); }
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; ++i) cin >> arr[i];
    int point = 0, traverse = 1, maxe;
    long long int sum = 0;
    while (point < n) {
      maxe = arr[point];
      while (traverse < n && !oppositeSigns(arr[point], arr[traverse])) {
        maxe = max(maxe, arr[traverse]);
        traverse++;
      }
      sum += maxe;
      point = traverse;
      traverse++;
    }
    cout << sum << endl;
  }
}
