CNOTE - Editorial

When I am running my code on ideone compiler ,the output is coming correct.But on running through it shows wrong answer.Can someone explain how to do subtasks?I made variable N and T long int still my answer is not getting accepted

How to solve it, if we are allowed to buy multiple notebooks instead of just one? Do we need to need to use Knapsack DP?

package easyLevel;

import java.util.Scanner;

public class ChefNNotebooks_CNOTE {

public static void main(String args[]){
	
	Scanner sc = new Scanner(System.in);
	
	int T = sc.nextInt();
	
	while(T > 0){
		
		String result = "UnluckyChef";
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int K = sc.nextInt();
		int N = sc.nextInt();
		
		while(N > 0){
			
			int P = sc.nextInt();
			int C = sc.nextInt();
			
			if(C <= K && P >= X-Y){
				result = "LuckyChef";
				break;
			}
			
			N--;
		}
		
		System.out.println(result);
		T--;
	}
}

}

gettinh WA, not sure why