/****************************>>>>HEADFILES<<<<****************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /****************************>>>>>DEFINE<<<<<*****************************/ #define fst first #define snd second #define root 1, N, 1 #define lson l, mid, (rt << 1) #define rson mid + 1, r, (rt << 1 | 1) #define __mid__ int mid = (l + r) >> 1 #define PB(a) push_back(a) #define MP(a,b) make_pair(a,b) #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) //#pragma comment(linker, "/STACK:1024000000,1024000000") typedef __int64 LL; const int INF = 0x3f3f3f3f; const int MAXN = 100000 + 5; /****************************>>>>SEPARATOR<<<<****************************/ int T, cas, N, M; char str[MAXN]; int main() { #ifndef ONLINE_JUDGE FIN; #endif // ONLINE_JUDGE scanf("%d", &T); while(T--) { scanf("%s", str); int cnt = 0; LL ans = 0; for(int i = 0; str[i]; i++) { if(str[i] == 'q') { cnt ++; ans += cnt; } else { cnt = 0; } } printf("%I64d\n", ans); } return 0; }