#include<stdio.h>#include<math.h>typedeflonglongll;char a[4];int s[9], p, n, i =6;
ll f(intx){if(x ==1)return(ll)2*pow(3, n -1)-1;if(x)return(ll)pow(2, n)-1;return(ll)pow(3, n -1);}intmain(){scanf("%d",&n);while(i--)scanf("%s", a), s[(a[0]-'A')*3+ a[1]-'A']= i;if(s[1]> s[2]){if(s[5]< s[3])
p =1;elseif(s[6]> s[7])
p =2;}elseif(s[7]< s[6])
p =1;elseif(s[3]> s[5])
p =2;printf("%lld",f(p));return0;}