#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    int n = second.length();
    vector<int> pre(n + 1);
    pre[0] = 0;
    for (int i = 1; i <= n; i++) {
      if (second[i - 1] == '+') {
        pre[i]++;
      } else
        pre[i]--;
      pre[i] += pre[i - 1];
    }
    long long total = 0;
    int ptr = 1;
    for (int i = 0; i <= n; i++) {
      while (ptr <= n && pre[ptr] >= -i) ptr++;
      total += (long long)ptr;
      if (ptr > n) {
        total--;
        break;
      }
    }
    cout << total << "\n";
  }
  return 0;
}
