#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define INF 0x3f3f3f3f #define MOD 1000000007 #define eps 1e-6 #define MAXN 1010 #define MAXM 27 #define dd {cout<<"debug"<= l; i --) #define doe(i, x) for(i = 1; i <= x; i ++) int n, num, num_id; int f[MAXN]; char str[MAXN]; LL fac[MAXN], fack[MAXN], sum; LL qpow(LL x, LL k) { LL res = 1; while(k) { if(k & 1) res = res * x % MOD; x = x * x % MOD; k >>= 1; } return res; } LL inv(LL a, LL x) { return qpow(a, x - 2); } void init() { fac[0] = fac[1] = 1; fack[0] = fack[1] = 1; for(int i = 2; i < MAXN; i ++) { fac[i] = (fac[i - 1] * i) % MOD; fack[i] = inv(fac[i], MOD); } } void read() { num = 0; num_id = 0; sum = 0; mes(f, 0); scanf("%s", str); int len = strlen(str); for(int i = 0; i < len; i ++) f[str[i] - 'a'] ++; for(int i = 0; i < MAXM; i ++) { if(f[i] % 2) { num ++; num_id = i; } sum += f[i]; } } void solve() { if(num > 1) printf("0\n"); else { LL ans = 1; if(num) { sum -= 1; f[num_id] -= 1; } sum /= 2; ans = fac[sum]; ans %= MOD; for(int i = 0; i < MAXM; i ++) if (f[i]) { ans = (ans * fack[f[i] / 2]) % MOD; } printf("%I64d\n", ans); } } int main() { init(); int T; scanf("%d", &T); while(T --) { read(); solve(); } return 0; }