#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int num;
    cin >> num;
    long long arr[num];
    for (int i = 0; i < num; ++i) {
      cin >> arr[i];
    }
    long long localMax = arr[0];
    long long sum = 0;
    for (int i = 1; i < num; ++i) {
      if (arr[i] * arr[i - 1] > 0) {
        if (arr[i] > localMax) localMax = arr[i];
      } else {
        sum = sum + localMax;
        localMax = arr[i];
      }
    }
    sum += localMax;
    cout << sum << endl;
  }
}
