#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll m;
           cin>>m;
           vll d(m),c(m);
           ll ans=0;
           rep(i,0,m){
             cin>>d[i]>>c[i];
             ans+=c[i];
           }
           ll cnt=0;
           rep(i,0,m){
             cnt+=d[i]*c[i];
             while(cnt>=10){
               ll c=cnt/10;
               ans+=c;
               cnt%=10;
               cnt+=c;
             }
           }
           cout<<ans-1<<endl;
}
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int N; cin >> N;

	int x, y;

	vector<int> y_x(8, -1);

	for (int i = 0; i < N; i++)
	{
		cin >> y >> x;

		y_x[y] = x;
	}

	vector<int> perm(8);

	for (int i = 0; i < 8; i++) { perm[i] = i; }

	bool ok = true;

	do
	{
		ok = true;

		for (int y = 0; y < 8; y++)
		{
			if (y_x[y] != -1 && perm[y] != y_x[y])
			{
				ok = false;
			}
		}

		if (ok == true)
		{
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					if (i != j)
					{
						if (i - perm[i] == j - perm[j] || i + perm[i] == j + perm[j])
						{
							ok = false;
						}
					}
				}
			}
		}

		if (ok == true)
		{
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					if (perm[i] == j)
					{
						cout << 'Q';
					}
					else
					{
						cout << '.';
					}
				}

				cout << endl;
			}
		}
	} while (next_permutation(perm.begin(), perm.end()));

	return 0;
}