#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long sum = 0;
    for (int i = 0; i < n;) {
      if (a[i] < 0) {
        long long mx = -1e10;
        while (i < n && a[i] < 0) {
          mx = max(mx, a[i]);
          i++;
        }
        sum += mx;
      } else if (a[i] > 0) {
        long long mx = 0;
        while (i < n && a[i] > 0) {
          mx = max(mx, a[i]);
          i++;
        }
        sum += mx;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
