#include #include #include using namespace std ; typedef long long LL ; typedef unsigned int ULL ; #define clr( a , x ) memset ( a , x , sizeof a ) #define root 1 , 1 , n #define ls o << 1 #define rs o << 1 | 1 #define lson ls , l , m #define rson rs , m + 1 , r const int MAXN = 100005 ; char s[MAXN] ; void solve () { scanf ( "%s" , s ) ; LL x = 0 ; LL ans = 0 ; for ( int i = 0 ; s[i] ; ++ i ) { if ( s[i] == 'q' ) { ++ x ; ans += x ; } else x = 0 ; } printf ( "%I64d\n" , ans ) ; } int main () { int T ; scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { solve () ; } return 0 ; }