#include <bits/stdc++.h>
using namespace std;
int main() {
  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 sum = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] > 0) {
        long long mx = -1;
        long long j = i;
        while (a[j] > 0 && j < n) {
          mx = max(mx, a[j]);
          j++;
        }
        sum += mx;
        i = j;
        i--;
      } else {
        long long mx = INT_MIN;
        long long j = i;
        while (a[j] < 0 && j < n) {
          mx = max(mx, a[j]);
          j++;
        }
        sum += mx;
        i = j;
        i--;
      }
    }
    cout << sum << endl;
  }
}
