#include <iostream>
#include <algorithm>
using namespace std;

int poramni(int broj) {
    if(broj == 0) {
        return 0;
    }

    int cifra = broj % 10;
    if(cifra==9){
        cifra=7;
    }
    return poramni(broj / 10) * 10 + cifra;
}
int main()
{
    int broj;
    int n;
    cin>>n;
    int niza[n];

    for(int i=0; i<n; i++){
        cin>>broj;
        niza[i]=poramni(broj);

    }
    sort(niza, niza+n);
   if(n>5){
    for(int i=0; i<5; i++){
        cout<<niza[i]<<endl;
    }
   }
   else{
    for(int i=0; i<n; i++){
        cout<<niza[i]<<endl;
    }
   }

    return 0;
}