#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <array>
typedef long long ll;
using namespace std;
const int N = 4010;
vector<int> e[N];
vector<array<ll, 4>> q;
int n, dfn[N], low[N], stk[N], instk[N], scc, tot, top, id[N];
bool check(ll sta1, ll end1, ll sta2, ll end2)
{
return end1 > sta2 && end2 > sta1; // 相交
}
void tarjan(int u)
{
dfn[u] = low[u] = ++ tot;
stk[ ++ top] = u, instk[u] = true;
for (auto v : e[u])
{
if (!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if (instk[v])
low[u] = min(low[u], dfn[v]);
}
if (dfn[u] == low[u])
{
++ scc;
int y;
do {
y = stk[top -- ];
instk[y] = false;
id[y] = scc;
} while (y != u);
}
}
int main()
{
scanf("%d", &n);
for (int i = 0;i < n;i ++ )
{
ll a, b, c, d, t;
scanf("%lld:%lld %lld:%lld %lld", &a, &b, &c, &d, &t);
ll l = a * 60 + b, r = c * 60 + d;
q.push_back({l, r, t, b});
}
for (int i = 0;i < n;i ++ )
for (int j = 0;j < n;j ++ )
{
if (i == j) continue;
int a = i * 2, b = j * 2;
// x ^ 1 表示 尾
// head and head
if (check(q[i][0], q[i][0] + q[i][2], q[j][0], q[j][0] + q[j][2]) )
{
e[a].push_back(b ^ 1); //
e[b].push_back(a ^ 1);
}
// head and trail
if (check(q[i][0], q[i][0] + q[i][2], q[j][1] - q[j][2], q[j][1]))
{
e[a].push_back(b);
e[b ^ 1].push_back(a ^ 1);
}
// trail and head
if (check(q[i][1] - q[i][2], q[i][1], q[j][0], q[j][0] + q[j][2]))
{
e[a ^ 1].push_back(b ^ 1);
e[b].push_back(a);
}
// trail and treil
if (check(q[i][1] - q[i][2], q[i][1], q[j][1] - q[j][2], q[j][1]))
{
e[a ^ 1].push_back(b);
e[b ^ 1].push_back(a);
}
}
for (int i = 0;i < 2 * n;i ++ ) if (!dfn[i]) tarjan(i);
for (int i = 0;i < n;i ++ )
if (id[i * 2] == id[i * 2 + 1]){
puts("NO");
exit(0);
}
puts("YES");
for (int i = 0;i < n;i ++ )
{
if (id[i * 2] < id[i * 2 + 1])
printf("%02lld:%02lld %02lld:%02lld\n",
q[i][0] / 60, q[i][0] % 60, (q[i][0] + q[i][2]) / 60, (q[i][0] + q[i][2]) % 60);
else
printf("%02lld:%02lld %02lld:%02lld\n",
(q[i][1] - q[i][2]) / 60, (q[i][1] - q[i][2]) % 60,
q[i][1] / 60, q[i][1] % 60);
}
}
~~~~~~