#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ int n; cin >> n; vector s(n); rep(i,0,n) cin >> s[i]; vector t(n); string ga(998244,'z'); rep(i,0,n){ vector cnt(26); rep(j,1,(int)s[i].size()){ cnt[s[i][j] - 'a']++; } rep(j,0,26){ if (cnt[j] >= 1){ cnt[j] -= 1; t[i].push_back('a'+j); break; } } rep(j,1,(int)s[i].size()){ if (cnt[s[i][j] - 'a'] >= 1){ cnt[s[i][j] - 'a'] -= 1; t[i].push_back(s[i][j]); }else{ t[i].push_back(s[i][0]); } } chmin(ga,t[i]); } vector ans(n); int cnt = 0; rep(i,0,n){ if (ga == t[i]){ cnt++; } } rep(i,0,n){ if (ga == t[i]){ ans[i] = n + 1 - cnt; } } rep(i,0,n){ cout << ans[i] << '\n'; } }