• + 0 comments

    Most of you used your high level knowledge to make it work, but here it is for begineers like me who would like to solve it with an easy method:

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arrObj;
    
        // data list
        ArrayList<ArrayList<Integer>> dataList = new ArrayList<>();
        // making array list to store data
        for (int i = 0; i < n; i++){
    
            int nArray = sc.nextInt();
            ArrayList<Integer> arr = new ArrayList<>();
            for(int j = 0; j < nArray; j++){
    
                arrObj = sc.nextInt();
    
                arr.add(arrObj);
    
            }
            // System.out.println(arr);
            dataList.add(arr);
        }
    
    
        int n2 = sc.nextInt();
        //query list
        // ArrayList<ArrayList<Integer>> queryList = new ArrayList<>();
        // making data list to fetch data or else print Erorr
        for (int i = 0; i < n2; i++){
    
            int row = sc.nextInt();
            int coloumn = sc.nextInt();
            // System.out.println(arr2);
            try{
                System.out.println(dataList.get(row-1).get(coloumn-1));
            }
            catch(Exception e){
                System.out.println("ERROR!");
            }
    
    
        }
    
    
    }
    

    }

    `