// Arup Guha
// 1/24/2020
// Solution to 2020 Mercer Contest Problem: Price is Right

import java.util.*;

public class price {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			// Get input.
			int limit = stdin.nextInt();
			int[] guesses = new int[4];
			for (int i=0; i<4; i++)
				guesses[i] = stdin.nextInt();
				
			// Initially no one wins.
			int winner = 0, curBest = 0;
			
			// Go through each guess.
			for (int i=0; i<4; i++) {
			
				// Doesn't count.
				if (guesses[i] > limit) continue;
				
				// Update if this is better than we've seen.
				if (guesses[i] > curBest) {
					curBest = guesses[i];
					winner = i+1;
				}
			}
			
			// Ta da!
			System.out.println(winner);
		}
	}
}