using System;
using System.Collections.Generic;
namespace Takmicenje5
{
    internal class Program
    {
        public static int[,] ucitajMatricu(int n, int m)
        {
            int[,] matrica = new int[m, n];
            for (int i = 0; i < n; i++)
            {
                string[] unos = Console.ReadLine().Split(' ');
                for (int j = 0; j < m; j++)
                {
                    matrica[i, j] = int.Parse(unos[j]);
                }
            }
            return matrica;
        }
        public static bool Proveri(int[,] m, int[,]u, int[,]l)
        {
            for (int i = 0; i < m.Length; i++)
            {
                for (int j = 0; j < m.Length; j++)
                {
                    if (m[i, j] > u[i, j] || m[i, j] < l[i, j]) return false;
                }
            }
            return true;
        }
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            string[] velicinatabele = Console.ReadLine().Split(' ');
            int n = int.Parse(velicinatabele[0]);
            int m = int.Parse(velicinatabele[1]);

            List<int[,]> l = new List<int[,]>();
            List<int[,]> u = new List<int[,]>();

            List<int[,]> momir = new List<int[,]>();
            List<string> resenje = new List<string>();
            for (int i = 0; i < T; i++)
            {
                l.Add(ucitajMatricu(n, m));
                u.Add(ucitajMatricu(n, m));

                resenje.Add("NE");
            }

            foreach(string s in resenje)
                Console.WriteLine(s);
            
        }
    }
}