import std.stdio;
import std.string, std.conv;
import std.array, std.algorithm;
import std.typecons;

void main() {
  for(int N; N = readln.chomp.to!int, N; ) {

    alias Tuple!(int, "name", int, "time") team;
    auto v = new team[N];

    foreach(i; 0 .. N) {
      auto s = readln.split.map!(to!int).array;
      int name = s[0];
      int c1 = s[1] * 60 + s[2];
      int c2 = s[3] * 60 + s[4];
      int c3 = s[5] * 60 + s[6];
      int c4 = s[7] * 60 + s[8];

      v[i] = tuple(name, c1 + c2 + c3 + c4);
    }
    sort!("a.time < b.time")(v);

    writeln(v[0].name);
    writeln(v[1].name);
    writeln(v[v.length - 2].name);
  }
}