// Arup Guha
// 8/3/2022
// Solution to 2022 February Silver USACO Problem: Email Filing

import java.util.*;
import java.io.*;

public class email {

	public static int nFold;
	public static int nMsg;
	public static int winSz;

	public static TreeSet<Integer> msgList;
	
	public static int[] fldList;
	public static int[] freq;
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		int nC = Integer.parseInt(stdin.readLine());
		
		// Process cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Get basic data.
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			nFold = Integer.parseInt(tok.nextToken());
			nMsg = Integer.parseInt(tok.nextToken());
			winSz = Integer.parseInt(tok.nextToken());
			msgList = new TreeSet<Integer>();
			fldList = new int[nMsg];
			freq = new int[nFold];
			
			// Read which folder each message must go to.
			tok = new StringTokenizer(stdin.readLine());
			for (int i=0; i<nMsg; i++) {
				fldList[i] = Integer.parseInt(tok.nextToken())-1;
				freq[fldList[i]]++;
			}
			
			// Run and output.
			if (go()) 	System.out.println("YES");
			else		System.out.println("NO");
		}
	}
	
	public static boolean go() {
	
		// Messages not filed away.
		TreeSet<Integer> ids = new TreeSet<Integer>();
		for (int i=1; i<=nMsg; i++)
			ids.add(i);

		// Set up treeset of messages for what is showing on right.
		int lowI = 1, highI = winSz;
		for (int i=0; i<winSz; i++) 
			msgList.add(fldList[i]*(nMsg+1) + (i+1));
				
		// i represents start of left window (to folders).
		// Since this never move backwards, this is how we scroll on the left.
		for (int i=0; i<=nFold-winSz; i++) {
			
			// Processing the RHS.
			while (true) {
			
				boolean didSomething = false;
				
				// Means we have no more to file away in this folder.
				if (i<nFold-winSz && freq[i] == 0) break;
				
				// Get the next message to file away.
				Integer curCode = msgList.higher(i*(nMsg+1));
				
				// If there is none, then we can't file anything else away...
				if (curCode == null) return ids.size() == 0;
				
				// Retrieve folder and message id.
				int cur = curCode/(nMsg+1);
				int curID = curCode%(nMsg+1);
				
				// We have something we can file away!
				if (cur < i+winSz) {
				
					// File away message.
					didSomething = true;
					freq[cur]--;
					msgList.remove(curCode);
					ids.remove(curID);
					
					// Key time to check if we're done!
					if (ids.size() == 0) return true;
					
					// See if window adds lower or upper item.
					Integer tmp = ids.higher(highI);
					
					// Slide down one more message.
					if (tmp != null) {
						if (curID == lowI) lowI = ids.higher(lowI);
						highI = tmp;
						msgList.add(fldList[highI-1]*(nMsg+1)+(highI));
					}
					
					// See if we can slide up a message.
					else {
						if (curID == highI) highI = ids.lower(highI);
						tmp = ids.lower(lowI);
						if (tmp != null) {
							lowI = tmp;
							msgList.add(fldList[lowI-1]*(nMsg+1)+(lowI));
						}
					}
				}
				
				// Nothing we can file away, so we must move this window down.
				else {
				
					Integer tmp = ids.higher(highI);
					if (tmp != null) {
						
						// Move window down one.
						didSomething = true;
						int lowCode = fldList[lowI-1]*(nMsg+1)+(lowI);
						lowI = ids.higher(lowI);
						msgList.remove(lowCode);
					
						// Slide down one more message.
						highI = tmp;
						msgList.add(fldList[highI-1]*(nMsg+1)+(highI));
					}					
				}
				
				// To avoid an infinite loop.
				if (!didSomething) break;
					
			} // end while-true
		} // end for
		
		// Only way we succeed.
		return ids.size() == 0;
	}
}