#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long int n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<long long> sub;
    int next = 0, j = 0;
    if (arr[0] < 0)
      next = 1;
    else
      next = -1;
    sub.push_back(arr[0]);
    for (int i = 1; i < n; i++) {
      if (next > 0) {
        if (arr[i] < 0) {
          if (sub[j] < arr[i]) sub[j] = arr[i];
        } else {
          sub.push_back(arr[i]);
          j++;
          next = -1;
        }
      } else {
        if (arr[i] > 0) {
          if (sub[j] < arr[i]) sub[j] = arr[i];
        } else {
          sub.push_back(arr[i]);
          j++;
          next = 1;
        }
      }
    }
    long long sum = 0;
    for (int i = 0; i < sub.size(); i++) {
      sum += sub[i];
    }
    cout << sum << "\n";
  }
}
