#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool compare(P a,P b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    int n;cin>>n;
    vector<int> perm(8);
    REP(i,8){
        perm[i] = i;
    }
    vector<P> xy(n);
    REP(i,n){
        int x,y; cin >> x >> y;
        xy[i] = P(x,y);
    }
    sort(ALL(xy),compare);
    do{ 
        vector<P> permutation(8);
        REP(i,8){
            permutation[i] = P(i,perm[i]);
        }
        bool flag1 = true;
        REP(i,n){
            if(!binary_search(ALL(permutation),xy[i], compare)) {
                flag1 = false; break;
            }
        }
        if(!flag1) continue;

        bool flag = true;
        REP(i,7){
            FOR(k,i+1,8){
                if(abs(k-i) == abs(perm[k]-perm[i])){
                    flag = false; break;
                }
            }
            if(!flag) break;
        }
        if(flag == true){
            REP(i,8){
                REP(k,8){
                    if(binary_search(ALL(permutation),P(i,k),compare)){
                        cout<<'Q';
                    }
                    else cout<<'.';
                }
                cout<<endl;
            }
            return 0;
        }
        

    }while(next_permutation(ALL(perm)));
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll d,len,ans=0,mi[20],me[20],cur[20];
void dfs(ll n,ll val,ll tmp){
//	cout<<"dfs "<<n<<' '<<val<<' '<<tmp<<' '<<d<<' '<<mi[len-n-1]<<' '<<mi[n-1]<<'\n';
	if(n>(len/2-1)){
		
		if(len%2) tmp*=10;
		if(val==d) ans+=tmp;
		return;
	}
	ll i=-9;
	while(i<=9&&i*(mi[len-n-1]-mi[n])+val<=d) i++;
	i--;cur[n]=i;
	dfs(n+1,val+i*(mi[len-n-1]-mi[n]),tmp*(me[i+10]-(n==0&&i>=0)));
	if(i==9) return;
	i++;cur[n]=i;
	dfs(n+1,val+i*(mi[len-n-1]-mi[n]),tmp*(me[i+10]-(n==0&&i>=0)));
} 
int main(){
	d=read();ll i,j;
	mi[0]=1;
	for(i=1;i<=18;i++) mi[i]=mi[i-1]*10;
	for(i=0;i<=9;i++) for(j=0;j<=9;j++) me[i-j+10]++; 
	for(len=0;len<=19;len++) dfs(0,0,1);
	printf("%lld\n",ans);
//	system("pause");
}