I am having a code which inputs:
vgxgp
3
2 4
2 5
7 14 
Expected output: Yes No Yes
1st input line contains a string S, the name of the item she is demanding.
2nd line contains an integer Q, the number of pairs of integers that used to say “Yes” or “No” to her. 
These pairs are given in order, following Q line, each contains 2 integers, a and b. (1-based indexing) I am getting error at if(line[a]==line[b]) as ArrayIndex out of bound.
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Test {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int t =Integer.parseInt(br.readLine());
        int[][] ar = new int[t][2];
        int k=0;
        for (int j = 0; j < t; j++) {       
            String[] input1=br.readLine().split(" ");
            for (int i = 0; i < 2; i++) {
                ar[k][i]=Integer.parseInt(input1[i]);     
            }
            k=k+1;
        }
        k=0;
        for (int i = 0; i < t-1; i++) {
            System.out.println(line[i]);    
            System.out.println(ar[k][0]);
            System.out.println(ar[k][1]);
            int a=ar[k][0];
            int b=ar[k][1];         
            System.out.println("hello"+line[i]);
            if(line[a]==line[b]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
                k = k + 1;
            }
        }
    }
}
 
     
     
    