// Arup Guha
// 9/25/2018
// Alternate Solution to 2018 NAQ Problem: Bingo Ties

import java.util.*;

public class bingoties_arup {
	
	public static int n;
	public static HashSet[][] cards;
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		
		// Create storage for cards.
		cards = new HashSet[n][5];
		for (int i=0; i<n; i++)
			for (int j=0; j<5; j++)
				cards[i][j] = new HashSet<Integer>();
		
		// Read each card.
		for (int i=0; i<n; i++) {
			for (int j=0; j<5; j++) {
				
				// Read in this row (row j on card i)
				for (int k=0; k<5; k++) 
					cards[i][j].add(stdin.nextInt());	
			}
		}
		
		// Wrapper to try ties with all pairs of cards.
		boolean res = false;
		int c1=-1, c2=-1;
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				
				// If we can tie, we finish!
				if (canTie(i, j)) {
					res = true;
					c1 = i+1;
					c2 = j+1;
					break;
				}
			}
			
			// Get out now!
			if (res) break;
		}
		
		// Output the result.
		if (res)
			System.out.println(c1+" "+c2);
		else
			System.out.println("NO TIES");
	}
	
	public static boolean canTie(int c1, int c2) {
		
		// Go through all possible pairs of rows.
		for (int i=0; i<5; i++) {
			for (int j=0; j<5; j++) {
				HashSet<Integer> and = common(cards[c1][i], cards[c2][j]);
				HashSet<Integer> or = either(cards[c1][i], cards[c2][j]);
				if (and.size() == 0) continue;
				if (and.size() == 5) return true;
				
				// Try removing x from the or set.
				for (Integer x: and) {
					or.remove(x);
					if (noSolves(or)) return true;
					or.add(x);
				}
			}
		}
		
		// If we get here, we can't do it.
		return false;
	}
	
	// Returns the intersection of a and b.
	public static HashSet<Integer> common(HashSet<Integer> a, HashSet<Integer> b) {
		HashSet<Integer> res = new HashSet<Integer>();
		for (Integer x: a)
			if (b.contains(x))
				res.add(x);
		return res;
	}
	
	// Returns the union of a and b.
	public static HashSet<Integer> either(HashSet<Integer> a, HashSet<Integer> b) {
		HashSet<Integer> res = new HashSet<Integer>();
		for (Integer x: a) res.add(x);
		for (Integer x: b) res.add(x);
		return res;
	}
	
	public static boolean noSolves(HashSet<Integer> set) {
		
		// Go through all relevant rows.
		for (int i=0; i<n; i++) {
			for (int j=0; j<5; j++) {
				
				// The intersection is how many in this row have it.
				HashSet<Integer> gotit = common(set, cards[i][j]);
				
				// Oops someone has already won :(
				if (gotit.size() == 5) return false;
			}
		}
		
		// If we get here, no row has solved it with what's called in set.
		return true;
	}

}
