#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,0,(int)s[i].size()){ cnt[s[i][j] - 'a']++; } t[i] = s[i]; sort(t[i].begin(), t[i].end()); //cout << t[i] << '\n'; if (t[i] == s[i]){ if (max(cnt) == 1){ swap(t[i][t[i].size() - 2], t[i][t[i].size() - 1]); } }else{ int ind = -1; rep(j,0,(int)s[i].size()){ if (s[i][j] != t[i][j]){ ind = j; break; } } assert(ind != -1); fill(cnt.begin(), cnt.end(), 0); rep(j,ind+1,(int)s[i].size()){ cnt[s[i][j] - 'a']++; } rep(j,0,26){ if (cnt[j] >= 1){ cnt[j] -= 1; t[i][ind] = 'a'+j; break; } } rep(j,ind+1,(int)s[i].size()){ if (cnt[s[i][j] - 'a'] >= 1){ cnt[s[i][j] - 'a'] -= 1; t[i][j] = s[i][j]; }else{ t[i][j] = s[i][ind]; } } } //cout << t[i] << '\n'; 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'; } }