import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] matrix = new int[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { matrix[i][j] = sc.nextInt(); } } int a = sc.nextInt(); int b = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); x--; y--; if (a == 1 && b == 2) { int temp = matrix[x][y]; matrix[x][y] = matrix[x + 1][y]; matrix[x + 1][y] = matrix[x + 1][y + 1]; matrix[x + 1][y + 1] = matrix[x][y + 1]; matrix[x][y + 1] = temp; } else if (a == 1 && b == 3) { up_to_down(matrix, x, y); transposition(matrix, x, y); } else if (a == 2 && b == 2) { int temp = matrix[x][y]; matrix[x][y] = matrix[x][y + 1]; matrix[x][y + 1] = matrix[x + 1][y + 1]; matrix[x + 1][y + 1] = matrix[x + 1][y]; matrix[x + 1][y] = temp; } else { left_to_right(matrix, x, y); transposition(matrix, x, y); } print(matrix); } private static void swap(int[][] matrix, int i1, int j1, int i2, int j2) { int temp = matrix[i1][j1]; matrix[i1][j1] = matrix[i2][j2]; matrix[i2][j2] = temp; } private static void up_to_down(int[][] matrix, int x, int y) { for (int j = 0; j < 3; j++) { swap(matrix, x, y + j, x + 2, y + j); } } private static void left_to_right(int[][] matrix, int x, int y) { for (int i = 0; i < 3; i++) { swap(matrix, x + i, y, x + i, y + 2); } } private static void transposition(int[][] matrix, int x, int y) { for (int i = 0; i < 3; i++) { for (int j = 0; j < i; j++) { swap(matrix, x + i, y + j, x + j, y + i); } } } private static void print(int[][] matrix) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } } }