https://codeforces.com/problemset/problem/1373/C
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e6+10;
LL s[N];
void solve(string ss)
{
LL res=0,n=ss.size();
for(int i=0;i<n;i++)
{
if(ss[i]=='+') s[i+1]=s[i]+1;
else s[i+1]=s[i]-1;
}
int pos=0;//s[0]可以当成一个哨兵,因为必定会执行一次
for(int i=0;i<=n;i++)
{
while(s[pos]+i>=0&&pos<n) pos++;
res+=pos;
if(s[pos]+i>=0) break;
}
cout<<res<<endl;
}
int main(void)
{
int t; cin>>t;
while(t--)
{
string s; cin>>s;
solve(s);
}
return 0;
}