#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

#define all(x)  x.begin(),x.end()
#define v(x) vector<x>
#define nl '\n'
#define fxd(x) fixed << setprecision(x)
template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;

struct item
{
    ll val;
    ll w;
    string type;
    ll date;
    string name;
};

bool cmp(const item& a, const item& b)
{
    if(a.val == b.val)
    {
        if(a.w == b.w)
        {
            if(a.type == b.type)
            {
                if(a.date == b.date)
                {
                    return a.name < b.name;
                }
                else
                {
                    return a.date < b.date;
                }
            }
            else
            {
                return a.type < b.type;
            }
        }
        else
        {
            return a.w < b.w;
        }
    }
    else
    {
        return a.val < b.val;
    }
}


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n; cin >> n;
    vector<item> arr(n);
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i].val >> arr[i].w >> arr[i].type >> arr[i].date >> arr[i].name;
    }

    sort(arr.begin(),arr.end(),cmp);
    for (int i = 0; i < n; i++)
    {
        cout << arr[i].val << " " << arr[i].w << " " << arr[i].type << " " << arr[i].date << " " << arr[i].name << nl;
    }
    
}