#include #include #include #include using namespace std; const int M = 1e9+7; const int N = 1010; typedef long long ll; char s[N]; int len; int c[30]; ll fac[N]; ll inv[N]; ll quipow(ll a, ll b) { ll tp = 1LL; while(b) { if(b&1) tp = (tp * a) % M; b >>= 1; a = (a * a) % M; } return tp; } void init() { //printf("-- %lld\n", quipow(3, 7)); fac[0] = fac[1] = 1; for(int i = 2; i < N; ++i) fac[i] = fac[i-1] * i % M; inv[N-1] = quipow(fac[N-1], M-2); for(int i = N-2; i >= 0; --i) inv[i] = inv[i+1] * (i+1) % M; inv[0] = 1; //printf("%lld %lld ---\n", fac[N-1], inv[N-1]); //for(int i = 0; i < 10; ++i) printf("%lld %lld ++\n", inv[i], fac[i]); } void solve() { sort(s, s+len); memset(c, 0, sizeof c); c[s[0]-'a'] = 1; for(int i = 1; i < len; ++i) { if(s[i] == s[i-1]) c[s[i] - 'a']++; else c[s[i] - 'a'] = 1; } int t = 0; for(int i = 0; i < 26; ++i) if(c[i]) c[t++] = c[i]; int odd = 0; for(int i = 0; i < t; ++i) if(c[i] & 1) odd++; if(odd > 1 || (odd == 1 && len % 2 == 0)) { puts("0"); return ; } //printf("t == %d len = %d\n", t, len); //for(int i = 0; i < t; ++i) printf("%d ", c[i]); puts(""); // ll ans = fac[len/2]; for(int i = 0; i < t; ++i) { ans = (ans * inv[c[i]/2]) % M; } printf("%I64d\n", ans); } int main() { init(); int T; scanf("%d", &T); while(T--) { scanf("%s", s); len = strlen(s); solve(); } return 0; }