#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    int f = (a[0] > 0);
    long long now = a[0];
    for (long long i = 1; i < n; i++) {
      if ((a[i] > 0) ^ f) {
        ans += now;
        now = a[i];
      }
      f = (a[i] > 0);
      now = max(now, a[i]);
    }
    ans += now;
    cout << ans << '\n';
  }
}
