#include <bits/stdc++.h>
using namespace std;
const long o = 1e6 + 5;
long t, n, len[2 * o];
string chuoi;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> chuoi;
    n = chuoi.size();
    chuoi = '.' + chuoi;
    long ktra = 0;
    for (long i = 1; i <= n; i++) {
      if (chuoi[i] == '-')
        ktra--;
      else
        ktra++;
      if (!len[ktra + o]) len[ktra + o] = i;
    }
    long long kq = 0;
    for (long i = 0; i <= n; i++) {
      if (len[(-i - 1) + o])
        kq += len[(-i - 1) + o];
      else {
        kq += n;
        break;
      }
    }
    cout << kq << '\n';
    ktra = 0;
    for (long i = 1; i <= n; i++) {
      if (chuoi[i] == '-')
        ktra--;
      else
        ktra++;
      len[ktra + o] = 0;
    }
  }
  return 0;
}
