#include <iostream>
#include <list>
using namespace std;

struct Student{
    string lastName;
    int year;
    int matan;
    int linal;
};
bool compareByLastName(const Student &student1, const Student &student2){
return (student1.lastName)<(student2.lastName);
}
bool compareByYear(const Student &student1, const Student &student2){
    return (student1.year)<(student2.year);
}
bool removeIfComparator(const Student &student1){
    return ((student1.matan)<60) or ((student1.linal<60));
}

void printList(list<Student> &lst){
    for(list<Student>::iterator it = lst.begin();it!=lst.end();it++){
        cout<<(*it).lastName<<" "<<(*it).year<<" "<<(*it).matan<<" "<<(*it).linal<<endl;
    }
}

int main(){
    Student firstStudent;
    list<Student> lst;
    for(int i=0;i<3;i++){
        cin>>firstStudent.lastName>>firstStudent.year>>firstStudent.matan>>firstStudent.linal;
        lst.push_back(firstStudent);
    }
    printList(lst);
    lst.sort(compareByLastName);
    cout<<"Sorted by last name list: ";
    printList(lst);
    lst.sort(compareByYear);
    cout<<"Sorted by year list: ";
    printList(lst);
    for(list<Student>::iterator it=lst.begin();it!=lst.end();it++){
        if((*it).matan>60 && (*it).linal>60){
            (*it).year++;
        }
    }
    lst.remove_if(removeIfComparator);
    cout<<"Updated list after exams: ";
    printList(lst);
}