Problem:
Look for the Winner!

The citizens of TKB City are famous for their deep love in elections and vote counting.
Today they hold an election for the next chairperson of the electoral commission.
Now the voting has just been closed and the counting is going to start.
The TKB citizens have strong desire to know the winner as early as possible during vote counting.

The election candidate receiving the most votes shall be the next chairperson.
Suppose for instance that we have three candidates A, B, and C and ten votes.
Suppose also that we have already counted six of the ten votes and the vote counts of A, B, and C are four, one, and one, respectively.
At this moment, every candidate has a chance to receive four more votes and so everyone can still be the winner.
However, if the next vote counted is cast for A, A is ensured to be the winner since A already has five votes and B or C can have at most four votes at the end.
In this example, therefore, the TKB citizens can know the winner just when the seventh vote is counted.

Your mission is to write a program that receives every vote counted, one by one, identifies the winner, and determines when the winner gets ensured.

Input

The input consists of at most 1500 datasets, each consisting of two lines in the following format.

n

c1 c2 … cn

n in the first line represents the number of votes, and is a positive integer no greater than 100.
The second line represents the n votes, separated by a space.
Each ci (1 ≤ i ≤ n) is a single uppercase letter, i.e. one of 'A' through 'Z'.
This represents the election candidate for which the i-th vote was cast.
Counting shall be done in the given order from c1 to cn.

You should assume that at least two stand as candidates even when all the votes are cast for one candidate.

The end of the input is indicated by a line containing a zero.

Output

For each dataset, unless the election ends in a tie, output a single line containing an uppercase letter c and an integer d separated by a space:
c should represent the election winner and d should represent after counting how many votes the winner is identified.
Otherwise, that is, if the election ends in a tie, output a single line containing `TIE'.

Sample Input

1
A
4
A A B B
5
L M N L N
6
K K K K K K
6
X X X Y Z X
10
A A A B A C A C C B
10
U U U U U V V W W W
0

Output for the Sample Input

A 1
TIE
TIE
K 4
X 5
A 7
U 8

Solution in JAVA (judge verdict: Accepted)

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main{

	static PrintWriter out;
	static InputReader ir;

	static void solve(){
		for(;;){
			int n=ir.nextInt();
			if(n==0)
				break;
			int ma=-1,idx=-1,sl=-1,idx2=-1;
			int[] a=new int[26];
			for(int i=0;i<n;i++){
				a[ir.next().charAt(0)-'A']++;
				for(int j=0;j<26;j++){
					if(a[j]>=ma){
						ma=a[j];
						idx=j;
					}
				}
				for(int j=0;j<26;j++){
					if(j==idx)
						continue;
					if(a[j]>=sl){
						sl=a[j];
						idx2=j;
					}
				}
				if(ma>sl+n-i-1){
					out.println(Character.toString((char)('A'+idx))+" "+Integer.toString(i+1));
					for(int j=i+1;j<n;j++)
						ir.next();
					break;
				}
				if(i==n-1&&ma==sl)
					out.println("TIE");
			}
		}
	}

	public static void main(String[] args) throws Exception{
		ir=new InputReader(System.in);
		out=new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer=new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

		public boolean hasNextByte() {
			if(curbuf>=lenbuf){
				curbuf= 0;
				try{
					lenbuf=in.read(buffer);
				}catch(IOException e) {
					throw new InputMismatchException();
				}
				if(lenbuf<=0) return false;
			}
			return true;
		}

		private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

		private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

		private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

		public boolean hasNext(){skip(); return hasNextByte();}

		public String next(){
			if(!hasNext()) throw new NoSuchElementException();
			StringBuilder sb=new StringBuilder();
			int b=readByte();
			while(!isSpaceChar(b)){
				sb.appendCodePoint(b);
				b=readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			int res=0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public long nextLong() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			long res = 0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public double nextDouble(){return Double.parseDouble(next());}

		public int[] nextIntArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a=new long[n];
			for(int i=0;i<n;i++) a[i]=nextLong();
			return a;
		}

		public char[][] nextCharMap(int n,int m){
			char[][] map=new char[n][m];
			for(int i=0;i<n;i++) map[i]=next().toCharArray();
			return map;
		}
	}
}