#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int mp = 0;
    int mn = INT_MIN;
    long long int s = 0;
    int p = 0, ne = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >= 0) {
        if (ne > 0) {
          s += mn;
          ne = 0;
        }
        if (mp <= a[i]) {
          mp = a[i];
          p = 1;
        }
        mn = INT_MIN;
      } else {
        if (p > 0) {
          s += mp;
          p = 0;
        }
        if (mn <= a[i]) {
          mn = a[i];
          ne = 1;
        }
        mp = 0;
      }
    }
    if (p != 0) s += mp;
    if (ne != 0) s += mn;
    cout << s << endl;
  }
}
