#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.length();
    long long pref[n + 1];
    if (s[0] == '+')
      pref[0] = 1;
    else {
      pref[0] = -1;
    }
    for (long long i = 1; i < n; i++) {
      if (s[i] == '+') {
        pref[i] = pref[i - 1] + 1;
      } else {
        pref[i] = pref[i - 1] - 1;
      }
    }
    long long res = 1;
    long long ans = 0;
    for (long long i = 0; i <= n; i++) {
      if (pref[i] == (-1 * res) && i != n) {
        ans = ans + i + 1;
        res++;
      } else if (i == n) {
        ans = ans + n;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
