#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int fe = arr[0], s, ts;
    if (fe > 0)
      s = 0;
    else
      s = 1;
    vector<int> v;
    for (int i = 1; i < n; i++) {
      if (arr[i] > 0)
        ts = 0;
      else
        ts = 1;
      if ((s ^ ts)) {
        v.push_back(i);
        s = ts;
      }
    }
    int k = 0, mx = INT_MIN;
    long long int sum = 0;
    if (v.empty()) {
      cout << *max_element(arr, arr + n) << endl;
      continue;
    }
    for (int i = 0; i < n; i++) {
      if (i == v[k]) {
        sum += mx;
        mx = arr[i];
        k++;
      } else
        mx = max(mx, arr[i]);
    }
    sum += mx;
    cout << sum << endl;
  }
}
