/*--------------------------------------------------------------*/
/* ACM ICPC 2007-2008                                           */
/* Northeastern European Regional Contest                       */
/* St Petersburg - Barnaul - Tashkent - Batumi, November 28, 200*/
/*--------------------------------------------------------------*/
/* Problem H. Hanoi Towers                                      */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Michael Dvorkin                        */
/*--------------------------------------------------------------*/
 
import java.io.*;
import java.util.*;

public class hanoi_md implements Runnable {

	private Scanner in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	
	private void solve() throws IOException {
		in = new Scanner(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] a = new int[6];
		int[] b = new int[6];
		for (int i = 0; i < 6; i++) {
			String s = in.next();
			a[i] = s.charAt(0) - 'A';
			b[i] = s.charAt(1) - 'A';
		}
		int[][] to = new int[n][3];
		long[][] opers = new long[n][3];
		for (int m = 0; m < n; m++) {
			for (int f = 0; f < 3; f++) {
				if (m == 0) {
					int go = -1;
					for (int i = 0; i < 6; i++) {
						if (a[i] == f) {
							go = b[i];
							break;
						}
					}
					to[m][f] = go;
					opers[m][f] = 1;
					continue;
				}
				long count = opers[m - 1][f];
				int small = to[m - 1][f];
				count++;
				int big = 3 ^ small ^ f;
				int s2 = to[m - 1][small];
				count += opers[m - 1][small];
				if (s2 == big) {
					to[m][f] = big;
					opers[m][f] = count;
					continue;
				}
				count++;
				int b2 = 3 ^ big ^ f;
				count += opers[m - 1][f];
				to[m][f] = b2;
				opers[m][f] = count;
			}
		}
		out.println(opers[n - 1][0]);
		in.close();
		out.close();
	}
	
	public static void main(String[] args) {
		new Thread(new hanoi_md()).start();
	}

}
