#include <bits/stdc++.h>
using namespace std;
long long a[200005], l[200005], r[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      l[i] = r[i] = 1;
    }
    for (int i = n - 2; i >= 0; --i) {
      if ((a[i + 1] < 0 && a[i] > 0) || (a[i + 1] > 0 && a[i] < 0)) {
        r[i] = r[i + 1] + 1;
      } else
        r[i] = r[i + 1];
    }
    int k = *max_element(r, r + n);
    long long maxsum = -10000000000;
    for (int i = 0; i < n; ++i) {
      if (r[i] == k) {
        long long sum = a[i];
        int x = i;
        for (int i = 0; i < k - 1; ++i) {
          if (a[x] < 0) {
            long long maxelement = -10000000000;
            for (int j = x + 1; j < n; ++j) {
              if (a[j] < 0) {
                x = j - 1;
                break;
              }
              maxelement = max(maxelement, a[j]);
            }
            sum += maxelement;
          } else if (a[x] > 0) {
            long long maxelement = -10000000000;
            for (int j = x + 1; j < n; ++j) {
              if (a[j] > 0) {
                x = j - 1;
                break;
              }
              maxelement = max(maxelement, a[j]);
            }
            sum += maxelement;
          }
        }
        maxsum = max(maxsum, sum);
      }
    }
    cout << maxsum << '\n';
  }
  return 0;
}
