#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long pre = 0, res = 0, cur = 0, ans = 0;
    for (int i = 0; i < s.size(); i++) {
      res = res + 1;
      if (s[i] == '+')
        cur++;
      else
        cur--;
      if (cur < 0) {
        cur = 0;
        ans += res + pre;
        pre += res;
        res = 0;
      }
    }
    cout << ans + s.size() << endl;
  }
}
