
object Main extends App {

  import scala.io.StdIn._

  var n = readLine.toInt
  while (n != 0) {
    val vote = readLine.trim.split(' ').map(_.charAt(0)).toList
    val voteCount = Array.tabulate(27){_ ⇒ 0}
    println(
      search(vote, voteCount, ('A' + 26).toChar, ('A' + 26).toChar) match{
        case Some((winner, count)) ⇒ s"$winner $count"
        case None ⇒ "TIE"
      }
    )
    n = readLine.toInt
  }
  def search(vote: List[Char], voteCount: Array[Int], first: Char = 'A', second: Char = 'A', count: Int = 0): Option[(Char, Int)] = {
    if (vote.size + voteCount(second - 'A') < voteCount(first - 'A')) Some(first, count)
    else vote match{
      case Nil ⇒
        if (voteCount(first - 'A') == voteCount(second - 'A')) None
        else Some(first, count)
      case `first`::t ⇒ voteCount(first - 'A') += 1
        search(t, voteCount, first, second, count + 1)
      case `second`::t ⇒ voteCount(second - 'A') += 1
        if (voteCount(first - 'A') > voteCount(second - 'A')) search(t, voteCount, first, second, count + 1)
        else search(t, voteCount, second, first, count + 1)
      case h::t ⇒ voteCount(h - 'A') += 1
        if (voteCount(second - 'A') > voteCount(h - 'A')) search(t, voteCount, first, second, count + 1)
        else if (voteCount(first - 'A') > voteCount(h - 'A')) search(t, voteCount, first, h, count + 1)
        else search(t, voteCount, h, first, count + 1)
    }
  }
}

