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