/**
 * @(#)fileIO.java
 *
 *
 * @author 
 * @version 1.00 2009/11/24
 */

import java.io.*;

public class q4 {
	
	public static int sumDig (int x){
		int sum = 0;
		
		while (x > 0) {
			
			if ((x / 10) != 0) {
				sum = sum + (x % 10);
				x = x / 10;
			}
			else {
				sum = sum + x;
				x = 0;
		    }
		}
		return sum;
	}

	
	public static void main(String[] args) throws IOException {
        
		String fileIN = "DATA4.txt";	
		String fileIN2 = "dic.txt";	
		String fileOUT = "OUT4.txt" ; 
		String fileOUT2 = "dic.txt" ; 
				
		BufferedReader inputStream1 = null;
		BufferedReader inputStream2 = null;
        PrintWriter outputStream1 = null; 
        PrintWriter outputStream2 = null;
        String characterRead = null;
        
        inputStream1 = new BufferedReader(new FileReader(fileIN));
		outputStream1 = new PrintWriter(new BufferedWriter(new FileWriter(fileOUT))); 
		outputStream2 = new PrintWriter(new BufferedWriter(new FileWriter(fileOUT2)));
			
		int[] data = new int[50000];
		for (int i = 0; i < 50000; i++) {
			
			//characterRead = inputStream.readLine();
			data[i] = ( (i * sumDig(i)) % 99999 );
			
			outputStream2.println(data[i]);
		}
		outputStream2.close();
	
		inputStream2 = new BufferedReader(new FileReader(fileIN2));
		
		int[] dic = new int[50000];
		String[] dic2 = new String[50000];
		int count = 0;
		for (int j = 0; j < 50000; j++){
			dic[j] = Integer.parseInt(inputStream2.readLine());
		}
		
		for (int k = 0; k< 50000; k++){
			dic2[k] = Integer.toString(dic[k]);
		}
		for (int i = 0; i < 5; i++) {
			
			characterRead = inputStream1.readLine();
			
			
			for (int l = 0; l < 50000; l++){
				if(dic2[l].length() >= characterRead.length() && dic2[l].substring(0, characterRead.length()).equals(characterRead))
					count++;	
			}
			
			outputStream1.println(count + "\n");
			count = 0;
		}
	
		inputStream1.close();
		inputStream2.close();
		outputStream1.close(); 
	}			


}

