#include <bits/stdc++.h>
using namespace std;
long long arr[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 0; i < n; ++i) {
      cin >> arr[i];
    }
    long long ans = 0;
    long long i = 0;
    while (i < n) {
      long long mx = arr[i];
      long long j = i + 1;
      while (j < n && arr[j] * mx > 0) {
        mx = max(mx, arr[j]);
        j++;
      }
      ans += mx;
      i = j;
    }
    cout << ans << endl;
  }
}
