#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long p, sum = 0, c;
    int n, i, j, k;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < n; i++) {
      if (a[i] > 0) {
        c = a[i];
        for (j = i + 1; j < n; j++) {
          if (a[j] > c)
            c = a[j];
          else if (a[j] < 0) {
            break;
          }
        }
        sum += c;
        j--;
        i = j;
      } else {
        c = a[i];
        for (j = i + 1; j < n; j++) {
          if (a[j] > c && a[j] < 0)
            c = a[j];
          else if (a[j] > 0) {
            break;
          }
        }
        sum += c;
        i = j - 1;
      }
    }
    cout << sum << "\n";
  }
}
