#include<bits/stdc++.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
int n;
cin>>n;
vector<string>a,b,c;
while(n--){
string s;
cin>>s;
sort(s.begin(),s.end(),less());a.push_back(s);c.push_back(s);
sort(s.begin(),s.end(),greater());b.push_back(s);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(auto &s : c){
int x=lower_bound(b.begin(),b.end(),s)-b.begin()+1;
sort(s.begin(),s.end(),greater());
int y=upper_bound(a.begin(),a.end(),s)-a.begin();
cout<<x<<" "<<y<<endl;
}
return 0;
}