#include <bits/stdc++.h>
using namespace std;
const int inf = 2e5 + 7;
int arr[inf];
int main() {
  int N;
  cin >> N;
  while (N--) {
    memset(arr, 0, sizeof(arr));
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
    long long sum = 0;
    int flag = 1;
    if (arr[0] < 0) flag = -1;
    for (int i = 0; i < n;) {
      int themax = (1e9 + 1) * (-1);
      while (arr[i] * flag > 0) {
        if (arr[i] > themax) themax = arr[i];
        i++;
      }
      flag = flag * (-1);
      sum += themax;
      themax = (1e9 + 1) * (-1);
      if (i >= n) break;
      while (arr[i] * flag > 0) {
        if (arr[i] > themax) themax = arr[i];
        i++;
      }
      sum += themax;
      flag = flag * (-1);
    }
    cout << sum << endl;
  }
  return 0;
}
