#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long int ma = 0, sum = 0;
    long long int mi = 0, j = 0;
    while (j < n) {
      if (a[j] > 0) {
        ma = a[j];
        for (int i = j + 1; i < n; i++) {
          if ((a[i] > ma) && (a[i] > 0))
            ma = a[i];
          else if (a[i] < 0) {
            j = i - 1;
            break;
          }
          if (i == (n - 1)) j = i;
        }
        sum += ma;
        j = j + 1;
      } else if (a[j] < 0) {
        mi = a[j];
        for (int k = j + 1; k < n; k++) {
          if ((a[k] > mi) && a[k] < 0) {
            mi = a[k];
          } else if (a[k] > 0) {
            j = k - 1;
            break;
          }
          if (k == n - 1) j = k;
        }
        sum += mi;
        j++;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
