const
	MaxN = 210;

VAR
	inFile, outFile : text;
	n, k, i, j, count, x, y, z : longint;
	val : boolean;
	a : array[0..MaxN, 0..MaxN] of longint;
	sol: array[0..MaxN, 0..MaxN, 0..MaxN] of boolean;
	mark : array[0..MaxN] of boolean;

BEGIN

	assign(inFile, 'ostrva.in');
	assign(outFile, 'ostrva.out');
	reset(inFile); rewrite(outFile);

	readln(inFile, n);
	for i := 1 to n do
		for j := 1 to n do
			read(inFile, a[i][j]);
	
	fillchar(mark, sizeof(mark), false);

	for count := 1 to n - 2 do begin
	
		// nalazenje tacke na konveksnom omotacu
		x := 0;
		for i := 1 to n - 1 do begin
			if (mark[i]) then continue;
			for j := i + 1 to n do
				if ((NOT mark[j]) AND (a[i][j] = 0)) then begin
					x := i;
					break;
				end;
			if (x <> 0) then break;
		end;
		mark[x] := true;

		// racunanje odgovora na sve upite koji sadrze tacku x (i,j,x)
		// i izbacivanje tacke x (updateovanje matrice a)
		for i := 1 to n - 1 do
			for j := i + 1 to n do
				if ((NOT mark[i]) AND (NOT mark[j])) then begin
					val := (a[x][i] > a[x][j]);
					sol[x][i][j] := val; sol[i][j][x] := val; sol[j][x][i] := val;
					sol[x][j][i] := NOT val; sol[j][i][x] := NOT val; sol[i][x][j] := NOT val;

					if (val) then
						a[i][j] := a[i][j] - 1
					else
						a[j][i] := a[j][i] - 1;
				end;

	end;

	readln(inFile, k);
	for i := 1 to k do begin
		read(inFile, x, y, z);
		if (sol[x][y][z]) then
			writeln(outFile, 'DA')
		else
			writeln(outFile, 'NE');
	end;

        close(inFile);
        close(outFile);

END.
