#include<bits/stdc++.h>
#define int __int128
using namespace std;
const int VZ=11;
int P;
struct node
{
int a[VZ][VZ];
};
void put(int x)
{
string s;
while(x)
{
s=char(x%10+48)+s;
x/=10;
}
cout<<s;
}
int read()
{
int a=0;char c;
while(c=getchar())
{
if(c<48||c>58) break;
a=a*10+c-48;
}
return a;
}
node cf(node a,node b)
{
node c;
for(int i=0;i<VZ;i++)
for(int j=0;j<VZ;j++)
c.a[i][j]=0;
for(int i=0;i<VZ;i++)
for(int j=0;j<VZ;j++)
for(int k=0;k<VZ;k++)
c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j]%P)%P;
return c;
}
node vec_pow_q(node n,int x)
{
node num=n,cnt;
for(int i=0;i<VZ;i++)
for(int j=0;j<VZ;j++)
cnt.a[i][j]=0;
for(int i=0;i<VZ;i++)
cnt.a[i][i]=1;
while(x)
{
if(x&1) cnt=cf(cnt,num);
x=x>>1;
num=cf(num,num);
}
return cnt;
}
vector<int> vec_ts_jz(int c[],node d)
{
vector<int> a;
for(int i=0;i<VZ;i++) a.push_back(0);
for(int i=0;i<VZ;i++)
for(int j=0;j<VZ;j++)
a[i]=(a[i]+c[j]*d.a[i][j]%P)%P;
return a;
}
int n,m,p,q,r,t,u,v,w,x,y,z;
void work()
{
n=read();P=read();
p=read();q=read();r=read();t=read();
u=read();v=read();w=read();
x=read();y=read();z=read();
node o=vec_pow_q((node){{
{p,q,1,0,1,0,0,0,r,t,1},
{1,0,0,0,0,0,0,0,0,0,0},
{1,0,u,v,1,0,1,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0},
{1,0,1,0,x,y,0,1,0,1,2},
{0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,w,0,0,0,0},
{0,0,0,0,0,0,0,z,0,0,0},
{0,0,0,0,0,0,0,0,1,2,1},
{0,0,0,0,0,0,0,0,0,1,1},
{0,0,0,0,0,0,0,0,0,0,1},
}},n-1);
int rt[]={3,1,3,1,3,1,w,z,1,1,1};
vector<int>tu=vec_ts_jz(rt,o);
cout<<"nodgd "; put(tu[1]);cout<<"\n";
cout<<"Ciocio ";put(tu[3]);cout<<"\n";
cout<<"Nicole ";put(tu[5]);cout<<"\n";
}
signed main() {
work();
return 0;
}