// Arup Guha
// 2/12/2020
// Solution to COP 4516 Final Individual Contest Problem: The Jumping Knight of Square County

import java.util.*;

public class blarge {

	// How knights jump.
	final public static int[] DX = {-2,-2,-1,-1,1,1,2,2};
	final public static int[] DY = {-1,1,-2,2,-2,2,-1,1};

	// Store the grid and where the knights are.
	public static int n;
	public static int numK;
	public static int[][] grid;
	public static int[][] knights;
	public static int[][] dist;
	public static int maxJump;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			// Parameters for case.
			n = stdin.nextInt();
			numK = stdin.nextInt();
			maxJump = stdin.nextInt();
			
			// Set up grids to read in.
			grid = new int[n][n];
			knights = new int[n][n];
			dist = new int[n][n];
			for (int i=0; i<n; i++) {
				Arrays.fill(knights[i], -1);
				Arrays.fill(dist[i], -1);
			}
			
			// Read in the grid.
			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					grid[i][j] = stdin.nextInt();
				
			// Read in where the knights are.
			for (int i=0; i<numK; i++) {
				int r = stdin.nextInt()-1;
				int c = stdin.nextInt()-1;
				knights[r][c] = i;
			}
			
			// This is where I am.
			int myr = stdin.nextInt()-1;
			int myc = stdin.nextInt()-1;
			
			// Start BFS from me, flipping search.
			LinkedList<Integer> q = new LinkedList<Integer>();
			q.offer(myr*n + myc);
			dist[myr][myc] = 0;
			
			// Run BFS.
			while (q.size() > 0) {
				
				// Next item.
				int curPos = q.poll();
				int x = curPos/n;
				int y = curPos%n;
				
				// Try each jump.
				for (int i=0; i<DX.length; i++) {
					
					// Here is where we go.
					int nX = x + DX[i];
					int nY = y + DY[i];
					
					// Can't use this.
					if (!inbounds(nX, nY)) continue;
					
					// Can't make the jump.
					if (Math.abs(grid[x][y] - grid[nX][nY]) > maxJump) continue;
					
					// New spot.
					if (dist[nX][nY] == -1) {
						dist[nX][nY] = dist[x][y] + 1;
						q.offer(nX*n+nY);
					}
				}
			}
			
			// Get best answer.
			int minJump = -1, minKnight = -1;
			
			// Go to all squares.
			for (int i=0; i<n; i++) {
				for (int j=0; j<n; j++) {
					
					// Knight is here!
					if (knights[i][j] != -1) {
						
						// Oops, we never got here.
						if (dist[i][j] == -1) continue;
						
						// A strictly better answer, update both.
						if (minJump == -1 || dist[i][j] < minJump) {
							minJump = dist[i][j];
							minKnight = knights[i][j];
						}
						
						// See if the knight number must be updated.
						else if (dist[i][j] == minJump) {
							minKnight = Math.min(minKnight, knights[i][j]);
						}
					}
				}
			}
			
			// Ta da!
			if (minJump == -1)
				System.out.println(-1);
			else
				System.out.println(minJump+" "+(minKnight+1));
		}
	}
	
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < n;
	}
}