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