import java.util.*;
import java.lang.*;
class Solution {

	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		
		int[] arr =new int[size];
 		
		for(int i = 0;i<size;i++){
			arr[i] = sc.nextInt();
		}
		
		
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
            
            int result = maxDistance(arr);
            System.out.println(result);
        }
	}
    public static int maxDistance(int[] arr) {
        // Code here
        HashMap<Integer,Integer> map = new HashMap<>();
        
        int n = arr.length;
        int maxDist = 0;
        for(int i=0;i<n; i++){
            if(map.containsKey(arr[i])){
                // Calculate actual distance from the FIRST occurrence
                int dist =  Math.abs(i - map.get(arr[i]) );
                maxDist = Math.max(dist,maxDist);
            }else{
                // Only store the very first time you see the number
                map.put(arr[i],i);
            }
            
        }
        
        return maxDist;
    }
}