#include using namespace std; int T, las, n, x, ans, maxi, tot; char s[3000005]; priority_queue q; int main() { scanf("%d", &T); while (T--) { scanf("%s", s + 1); while (q.size()) q.pop(); las = 0; n = strlen(s + 1); for (int i = 1; i <= n; i++) if (s[i] == '^') { q.push(i - las); las = i; } q.push(n + 1 - las); x = 1 << 21; ans = 0, tot = 0; while (x >= 2) { if (q.size() && q.top() >= x) { maxi = q.top(); q.pop(); maxi -= x; ans += x; if (maxi > 0) q.push(maxi); } x >>= 1; } while (q.size()) { maxi = q.top(); q.pop(); tot += maxi; } if (tot & 1) ans++; printf("%d\n", ans); } return 0; }