#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    long arr[n];
    for (int j = 0; j < n; j++) {
      cin >> arr[j];
    }
    long maxs = 0, mins = 0;
    long sum = 0, neg_count = 0, pos_count = 0;
    for (int j = 0; j < n; j++) {
      if (arr[j] > 0 && j != n - 1) {
        pos_count++;
        neg_count = 0;
        if (pos_count == 1) {
          maxs = arr[j];
        }
        if (arr[j + 1] > 0) {
          if (maxs < arr[j + 1]) {
            maxs = arr[j + 1];
          }
        } else {
          sum += maxs;
        }
      } else if (arr[j] < 0 && j != n - 1) {
        neg_count++;
        pos_count = 0;
        if (neg_count == 1) {
          mins = arr[j];
        }
        if (arr[j + 1] < 0) {
          if (mins < arr[j + 1]) {
            mins = arr[j + 1];
          }
        } else {
          sum += mins;
        }
      } else {
        if (arr[j] < 0 && arr[j - 1] > 0) {
          sum += arr[j];
        } else if (arr[j] > 0 && arr[j - 1] < 0) {
          sum += arr[j];
        } else if (arr[j] < 0 && arr[j - 1] < 0) {
          sum += mins;
        } else {
          sum += maxs;
        }
      }
    }
    cout << sum << endl;
  }
}
