#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int t, n, i, sum;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int a[n];
    sum = 0;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) {
      if (a[i] < 0 && i < n) {
        long long int l = a[i];
        while (a[i] < 0 && i < n) {
          if (l < a[i]) l = a[i];
          i++;
        }
        sum = sum + l;
      }
      if (a[i] > 0 && i < n) {
        long long int l = a[i];
        while (a[i] > 0 && i < n) {
          if (l < a[i]) l = a[i];
          i++;
        }
        sum = sum + l;
      }
      i = i - 1;
    }
    cout << sum << endl;
  }
  return 0;
}
