#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define x first
#define y secound
using namespace std;

inline int read()
{
	int num=0,f=1;char ch=getchar();
	while(!((ch<='9'&&ch>='0')||ch=='-'))ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=num*10+ch-'0',ch=getchar();
	return num*f;
}

const int M=510;
const int all=(1<<20)-1;
int n,Mod,dp[25][1<<20];

void add(int &a,int b){a=(a+b>=Mod?a+b-Mod:a+b);}

signed main()
{
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	n=read(),Mod=read();
	dp[1][1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=0;j<(1<<(i-1));j++)
			for (int k=1;k<i;k++)
				add(dp[i][(j|1<<(i-1))&(all^(1<<(k-1)))],dp[i-1][j]);
		int res=0;
		for (int j=0;j<(1<<i);j++)
		{
			int k=0;
			for (int w=0;w<i;w++)
				k|=(((j>>w)&1)^1)<<(i-w-1);
			add(res,dp[i][j]*dp[i][k]%Mod);
			cout<<j<<' '<<dp[i][j]<<'\n';
		}
		cout<<res<<"\n";
	}
	return 0;
}
/*
20 998244353
*/
