import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		int balance = 0;
		int lo = 0;
		long res = s.length;
		foreach (i, char c; s)
		{
			balance += (c == '+') ? +1 : -1;
			if (lo > balance)
			{
				lo = balance;
				res += i + 1;
			}
		}
		writeln (res);
	}
}
