/* ********************************* Author :clogos Created Time :2016/10/01 19:00:52 File Name :A.cpp ********************************** */ #include #define IOS ios::sync_with_stdio(0);cin.tie(0); #define IN freopen("in", "r", stdin); #define OUT freopen("out", "w", stdout); using namespace std; const int N = 100000 + 10; char str[N]; int main() { int cases; scanf("%d", &cases); while(cases--) { scanf("%s", str); int n = strlen(str); int tot = 0; long long ans = 0; for(int i = 0; i < n; ++i) { if(str[i] == 'q') tot++; else { ans += 1LL * tot * (tot+1) / 2; tot = 0; } } ans += 1LL * tot * (tot+1) / 2; printf("%lld\n", ans); } return 0; }