#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m, sum = 0;
  cin >> m;
  while (m > 0) {
    m--;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    sum = 0;
    if (a[0] > 0) {
      for (i = 0; i < n;) {
        int sum1 = 0, sum2 = INT_MIN;
        while (a[i] > 0 && i < n) {
          sum1 = max(sum1, a[i]);
          i++;
        }
        while (a[i] < 0 && i < n) {
          sum2 = max(sum2, a[i]);
          i++;
        }
        if (sum2 == INT_MIN) {
          sum2 = 0;
          sum = sum + sum1 + sum2;
        } else
          sum = sum + sum1 + sum2;
      }
      cout << sum << endl;
    } else {
      for (i = 0; i < n;) {
        int sum1 = 0, sum2 = INT_MIN;
        while (a[i] < 0 && i < n) {
          sum2 = max(sum2, a[i]);
          i++;
        }
        while (a[i] > 0 && i < n) {
          sum1 = max(sum1, a[i]);
          i++;
        }
        if (sum2 == INT_MIN) {
          sum2 = 0;
          sum = sum + sum1 + sum2;
        } else
          sum = sum + sum1 + sum2;
      }
      cout << sum << endl;
    }
  }
}
