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