#include #include #include #include using namespace std; typedef long long int ll; const ll N = 20, MOD = 1000000007; ll n; string crd[N]; ll dp[1 << N] = {}, ans[N] = {},fact[N+1]; int nmb(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } void factorial() { fact[0] = 1; for (int i = 1; i <= N; i++)fact[i] = (fact[i - 1] * i) % MOD; } int main() { cin >> n; factorial(); for (int i = 0; i < n; i++) { cin >> crd[i]; crd[i] += " "; } sort(crd, crd + n); for (int s = 0; s < (1 << n); s++) { for (int i = 0; i < n; i++) { if ((s >> i) & 1)continue; int val=1; for (int j = i - 1; j >= 0; j--) { if ((s >> j) & 1)continue; for (int k = 0; k < crd[i].size(); k++) { if (crd[i][k] != crd[j][k]) { val = k + 1; break; } } break; } for (int j = i + 1; j> j) & 1)continue; for (int k = 0; k < crd[i].size(); k++) { if (crd[i][k] != crd[j][k]) { val = max(val,k + 1); break; } } break; } dp[s | (1 << i)] = (dp[s | (1 << i)] + dp[s] + (val*fact[nmb(s)])%MOD) % MOD; } } for (int s = 1; s < (1 << n); s++)ans[nmb(s) - 1] = (ans[nmb(s) - 1] + dp[s]) % MOD; for (int i = 0; i < n; i++)cout << ans[i] << endl; return 0; }