#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, i, n, a[200000], s, ma;
  cin >> t;
  while (t--) {
    s = 0;
    cin >> n;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) {
      if (a[i] > 0) {
        ma = 0;
        while (a[i] > 0) {
          ma = max(ma, a[i]);
          i++;
        }
        s += ma;
        i--;
      } else {
        ma = -1000000000;
        while (a[i] < 0) {
          ma = max(a[i], ma);
          i++;
        }
        s += ma;
        i--;
      }
    }
    cout << s << "\n";
  }
}
