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