#include <bits/stdc++.h>
using namespace std;
bool comp(int num, bool negative) {
  if (negative && num < 0) return true;
  if (!negative && num > 0) return true;
  return false;
}
long long max_sum(vector<int> arr) {
  long long max_sum = 0;
  int i = 0;
  while (i < arr.size()) {
    bool negative = arr[i] < 0;
    int maxi = INT_MIN;
    while (i < arr.size() && comp(arr[i], negative)) {
      maxi = ((arr[i]) > (maxi) ? (arr[i]) : (maxi));
      i++;
    }
    max_sum += maxi;
  }
  return max_sum;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) cin >> arr[i];
    cout << max_sum(arr) << "\n";
  }
}
