using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
public class Solver
{
struct Pair
{
public int from, to;
public Pair(int f, int t) : this() { from = f; to = t; }
}
public void Solve()
{
var N = int.Parse(Console.ReadLine());
var P = new Pair[N];
for (int i = 0; i < N; i++)
{
var a = Console.ReadLine().Split('-').Select(x => int.Parse(x)).ToArray();
if (a[0] % 10 < 5)
a[0] = (a[0] / 10) * 10;
else a[0] = (a[0] / 10) * 10 + 5;
if (a[1] % 10 > 5)
a[1] = ((a[1] / 10) + 1) * 10;
else if (a[1] % 10 > 0)
a[1] = (a[1] / 10) * 10 + 5;
P[i] = new Pair(a[0], a[1]);
}
Array.Sort(P, (l, r) => l.from.CompareTo(r.from));
int id = 0;
while (id < N)
{
var s = P[id].from;
var e = P[id].to;
int j = id;
while (j < N && P[j].from <= e)
{
e = Math.Max(P[j].to, e);
j++;
}
id = Math.Max(id + 1, j);
IO.Printer.Out.WriteLine("{0}-{1}", s, e);
}
}
internal IO.StreamScanner sc;
static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
}
#region Main and Settings
static class Program
{
static void Main(string[] arg)
{
#if DEBUG
var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
Debug.AutoFlush = false;
var sw = new Watch(); sw.Start();
IO.Printer.Out.AutoFlush = true;
try
{
#endif
var solver = new Solver();
solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
solver.Solve();
IO.Printer.Out.Flush();
#if DEBUG
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Console.Error.WriteLine(ex.StackTrace);
}
finally
{
sw.Stop();
Console.ForegroundColor = ConsoleColor.Green;
Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
Debug.Close();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
#endif
}
}
#endregion
}
#region IO Helper
namespace Solver.IO
{
public class Printer : System.IO.StreamWriter
{
static Printer()
{
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
}
public static Printer Out { get; set; }
public static Printer Error { get; set; }
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
public void Write<T>(string format, IEnumerable<T> source) { Write(format, source.OfType<object>().ToArray()); }
public void WriteLine<T>(string format, IEnumerable<T> source) { WriteLine(format, source.OfType<object>().ToArray()); }
}
public class StreamScanner
{
public StreamScanner(System.IO.Stream stream) { iStream = stream; }
private readonly System.IO.Stream iStream;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
private bool eof = false;
public bool IsEndOfStream { get { return eof; } }
const byte lb = 33, ub = 126, el = 10, cr = 13;
public byte read()
{
if (eof) throw new System.IO.EndOfStreamException();
if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
return buf[ptr++];
}
public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
public string Scan()
{
if (eof) throw new System.IO.EndOfStreamException();
StringBuilder sb = null;
var enc = System.Text.UTF8Encoding.Default;
do
{
for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
if (ptr < len) break;
ptr = 0;
if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
} while (true);
do
{
var f = ptr;
for (; ptr < len; ptr++)
if (buf[ptr] < lb || ub < buf[ptr])
//if (buf[ptr] == cr || buf[ptr] == el)
{
string s;
if (sb == null) s = enc.GetString(buf, f, ptr - f);
else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
ptr++; return s;
}
if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
else sb.Append(enc.GetChars(buf, f, len - f));
ptr = 0;
}
while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
eof = true; return (sb != null) ? sb.ToString() : "";
}
public long Long()
{
long ret = 0; byte b = 0; bool isMynus = false;
const byte zr = 48, nn = 57, my = 45;
do b = read();
while (b != my && (b < zr || nn < b));
if (b == my) { isMynus = true; b = read(); }
for (; true; b = read())
if (b < zr || nn < b)
return isMynus ? -ret : ret;
else ret = ret * 10 + b - zr;
}
public int Integer()
{
int ret = 0; byte b = 0; bool isMynus = false;
const byte zr = 48, nn = 57, my = 45;
do b = read();
while (b != my && (b < zr || nn < b));
if (b == my) { isMynus = true; b = read(); }
for (; true; b = read())
if (b < zr || nn < b)
return isMynus ? -ret : ret;
else ret = ret * 10 + b - zr;
}
public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
public void Flush() { iStream.Flush(); }
}
}
#endregion
#region Extension
namespace Solver.Ex
{
static public partial class EnumerableEx
{
static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
}
}
#endregion
#region HashMap
class HashMap<K, V> : Dictionary<K, V>
{
new public V this[K i]
{
get
{
V v;
return TryGetValue(i, out v) ? v : base[i] = default(V);
}
set { base[i] = value; }
}
}
#endregion