import java.util.*; public class Main { static final int MAX_N = 30; static int N; static boolean[][] visited = new boolean[MAX_N][MAX_N]; static int[][] matrix = new int[MAX_N][MAX_N]; static int[][] D = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static int cnt = 0; static List list = new ArrayList(); static class Point{ Point(int r, int c, int d){ row = r; col = c; dist = d; } int row, col, dist; } p..