import java.io.*;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;

import java.lang.Math;

class Position {

    public int x, y;

    Position (int gx, int gy){
	x = gx;
	y = gy;
    }
    
} // class HotSpot

class HotSpot {
	
	private int d, intensity;
	private Position pos;
	
	HotSpot (Position p, int dist, int i){
		pos = p;
		d = dist;
		intensity = i;
	} //HotSpot
	
	public int getIntensity() {
		return intensity;
	} // get Intensity

	public boolean canReach(Position testPos) {
		return ((Math.abs(pos.x -  testPos.x)) <= d & 
				(Math.abs(pos.y - testPos.y) <= d));
 	} // canReach

} // class HotSpot


class ContestInput {
	//String 
//int 
	/** buffered character input stream */
    protected BufferedReader in =
    	new BufferedReader( new InputStreamReader( System.in ) );

	/** the tokenizer is instatiated for each line read by readLine( ). */
    protected StringTokenizer t;

    /** reads the next line of input and creates the associated StringTokenizer. */
    public void readLine( ) {
		try { t = new StringTokenizer( in.readLine( ) );
		} catch ( IOException e2 ) {
			System.err.println( "*** IO Exception ***" );
			System.exit( 1 );
		}
	}

	public int 		tokenCount( ) 	{ return t.countTokens( ); }
	public boolean 	hasMore( ) 		{ return t.hasMoreTokens( ); }

	///////////////////////////////////////////////   Integer types:

	/** consumes the next input token and converts into a short value
		@return		short value represented by the next token
	 */
	public short nextShort( ) {
		try { return Short.parseShort( t.nextToken( ) );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		} catch( NumberFormatException e1 ) {
			System.err.println( e1.getMessage( ) );
			System.err.println( "ist keine gültige short" );
		}
		return 0;
	 } // nextShort



	/** consumes the next input token and converts into a int value
		@return		int value represented by the next token
	 */
	public int nextInt( ) {
		try { return Integer.parseInt( t.nextToken( ) );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		} catch( NumberFormatException e1 ) {
			System.err.println( e1.getMessage( ) );
			System.err.println( "ist keine gültige int" );
		}
		return 0;
	 } // nextInt



	/** consumes the next input token and converts into a long value
		@return		long value represented by the next token
	 */
	public long nextLong( ) {
		try { return Long.parseLong( t.nextToken( ) );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		} catch( NumberFormatException e1 ) {
			System.err.println( e1.getMessage( ) );
			System.err.println( "ist keine gültige long" );
		}
		return 0;
	 } // nextLong



	///////////////////////////////////////////////   Character:

	/** consumes the next input token and converts into a character.
		Attention: single characters must be separated by
		white space characters.
		@return		charcter represented by the next token
	 */
	public char nextChar( ) {
		return t.nextToken( ).charAt( 0 );
	 } // nextchar


	///////////////////////////////////////////////   Boolean:

	/** consumes the next input token and converts into a boolean value
		@return		boolean value represented by the next token
	 */
	public boolean nextBoolean( ) {
		return new Boolean( t.nextToken( ) ).booleanValue( );
	 } // nextBoolean



	///////////////////////////////////////////////   Float/Double:

	/** consumes the next input token and converts into a float value
		@return		float value represented by the next token
	 */
	public float nextFloat( ) {
		try { return new Float( t.nextToken( ) ).floatValue( );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		} catch( NumberFormatException e1 ) {
			System.err.println( e1.getMessage( ) );
			System.err.println( "ist keine gültige float" );
		}
		return Float.NaN;
	 } // nextFloat


	/** consumes the next input token and converts into a double value
		@return		double value represented by the next token
	 */
	public double nextDouble( ) {
		try { return new Double( t.nextToken( ) ).doubleValue( );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		} catch( NumberFormatException e1 ) {
			System.err.println( e1.getMessage( ) );
			System.err.println( "ist keine gültige double" );
		}
		return Double.NaN;
	 } // nextDouble


	///////////////////////////////////////////////   String:

	public String nextString( ) {
		try { return t.nextToken( );
		} catch( NoSuchElementException e0 ) {
			System.err.println( "No more input available" );
		}
		return "";
	 } // nextString

} // class ContestInput

public class rats {

    public static void main( String args[ ] ) {
	ContestInput in = new ContestInput();
	in.readLine();
	int numberOfScenarios = in.nextInt();
		
	Position pos;
	int d, n, x, y, i;
	HotSpot hotSpots[];

	for(int k = 0; k < numberOfScenarios; k++) { //loop for every scenario
	    //System.err.println("Starting scenario");
	    in.readLine();
	    d = in.nextInt();

	    in.readLine();
	    n = in.nextInt();

	    hotSpots = new HotSpot[n]; 
	    for(int j = 0; j < n; j++){  //read Hot-Spot-Data and save them
		in.readLine();       //in hotSpots[]
		x = in.nextInt();
		y = in.nextInt();
		i = in.nextInt();
		pos = new Position(x,y);
		hotSpots[j] = new HotSpot(pos, d, i);
	    }//for(HotSpots)
	    

	    //System.err.println("Read input");
	    
	    int iresult = 0;
	    int xresult = 0;
	    int yresult = 0;

	    pos = new Position(0,0);
	    
	    for (x=0; x < 1025; x++){
		for (y=0; y < 1025; y++){ //loop for every Position in the grid
		    
		    //System.err.println("Looking at " + x + "," + y);
		    int tempiresult = 0;
		    
		    pos.x = x;
		    pos.y = y;

		    for (int m=0; m<n; m++){ //loop for every HotSpot
			
 				//add intensity of every reachable HotSpot: 
			
			if (hotSpots[m].canReach(pos))
			    tempiresult+= hotSpots[m].getIntensity(); 
			
			
		    }//for m(hotSpots)
		    
		    if (tempiresult > iresult) { //new best position found
			
			//System.err.println("New best solution found");
			iresult = tempiresult; //save new best position
			xresult = x;
			yresult = y;
			
		    } // if
		    
		}//for y
		//System.err.print(x+ " "); 
		System.gc();



	    }//for x
	    
	    //print result: 
	    System.out.println(xresult + " " + yresult + " " + iresult);
	    
	}// for(scenarios)
		
    } // main( )
    
} // class rats

