#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  for (int i = 0; i < t; i += 1) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (int j = 0; j < n; j += 1) {
      cin >> a[j];
    }
    long long int ma = a[0], sum = 0;
    for (int j = 1; j < n; j += 1) {
      if (a[j] * ma < 0) {
        sum += ma;
        ma = a[j];
      } else {
        ma = max(ma, a[j]);
      }
    }
    sum += ma;
    cout << sum << endl;
  }
}
