//package Main; import java.util.Scanner; public class Main { static int [][] mat=new int [2][2]; static int [][] unit=new int [2][2]; static int [][] as=new int [2][2]; //static Solve ans; static int a,b,n; static int mod=7; public static void main(…