#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int i;
    for (i = 0; i < n; i++) cin >> a[i];
    int len = 1;
    int dpLen[n];
    for (i = 0; i < n; i++) dpLen[i] = 1;
    for (i = 1; i < n; i++) {
      if ((a[i] > 0 && a[i - 1] > 0) || (a[i] < 0 && a[i - 1] < 0)) {
        dpLen[i] = len;
        continue;
      } else {
        dpLen[i] = len + 1;
        len = len + 1;
      }
    }
    vector<long long> dpSum;
    dpSum.push_back(0);
    int j;
    i = 0, j = 1;
    long long int mx = a[0];
    while (i < n) {
      mx = a[i];
      j = i + 1;
      while (dpLen[j] == dpLen[j - 1] && j < n) {
        if (a[j] > mx) mx = a[j];
        j++;
      }
      i = j;
      dpSum.push_back(mx + dpSum.back());
    }
    cout << dpSum.back() << '\n';
  }
}
