import java.util.*; public class LifeGame { static final boolean safe_slow_version = false; public static void main( String[] arg ) { int nCase = 1; for(Scanner sc = new Scanner(System.in) ;; ++nCase) { // read the first line of the input int N=sc.nextInt(), M=sc.nextInt(), L=sc.nextInt(); if( N==0 && M==0 && L==0 ) break; assert 1<=N && N<=6 : "\n N (hexmap size) is out-of-range"; assert 2<=M && M<=1000000000 : "\n M (modulo value) is out-of-range"; assert 1<=L && L<=1000000000 : "\n L (iteration) is out-of-range"; // read the initial state int S = 3*N*(N-1)+1; // Size of the hex-map long[] Ini = new long[S]; for(int i=0; i