#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 sum = 0, mx;
    bool flag;
    if (a[0] < 0)
      flag = 0;
    else
      flag = 1;
    for (int i = 0; i < n; i++) {
      mx = a[i];
      while (i < n && flag == 0 && a[i] < 0) mx = max(mx, a[i++]);
      while (i < n && flag == 1 && a[i] > 0) mx = max(mx, a[i++]);
      flag = !flag;
      sum += mx;
      i--;
    }
    cout << sum << "\n";
  }
  return 0;
}
