#include <iostream>
using namespace std;
int main() {
int len;
while(cin>>len){
int* ary = new int[len];//創儲存完整數字的動態陣列
for(int i = 0 ; i < len ; i++){//輸入進動態陣列裡
cin>>ary[i];
}
//比個位數大小
for(int i = 0 ; i < len ; i++){
for(int j = 0 ; j < len-1 ; j++){
if((ary[j]%10)>(ary[j+1]%10)){
int temp = ary[j];
ary[j] = ary[j+1];
ary[j+1] = temp;
}
}
}
//確認個位數一樣再比大小,小的排後面
for(int i = 0 ; i < len ; i++){
for(int j = 0 ; j < len-1 ; j++){
if((ary[j]%10)==(ary[j+1]%10)&&ary[j]<ary[j+1]){
int temp = ary[j];
ary[j] = ary[j+1];
ary[j+1] = temp;
}
}
}
for(int i = 0 ; i < len ; i++){
cout << ary[i] << " ";
}
cout << endl;
delete[]ary;//回收
}
}