#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    signed long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    signed long long int sum = 0;
    int i = 0;
    bool pos;
    while (i < n) {
      int m = a[i++];
      pos = (m > 0);
      while (i < n) {
        if ((a[i] > 0) != pos) break;
        m = ((m >= a[i++]) ? m : a[i++]);
      }
      sum += 1LL * m;
    }
    cout << sum << "\n";
  }
  return 0;
}
