#include <bits/stdc++.h>
using namespace std;
int s,n,c[1000004],p[1000004];
struct str
{
    int a,b;
    bool operator < (const str & o) const
    {
        if((a-b)<(o.a-o.b)) return true;
        return false;
    }
};

void print_prio(priority_queue <str> pq)
{
	while (!pq.empty())
	{
		cout << (pq.top()).a << ' ' << (pq.top()).b << endl;
		pq.pop();
	}
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("22.inp","r",stdin);
    //freopen("22.out","w",stdout);
    cin>>n;
    priority_queue<str> q;
    for(int i=1;i<=n;i++) cin>>c[i]>>p[i];
    for(int i=1;i<=n;i++)
    {
        q.push({c[i],p[i]});
        s+=c[i];
        cout << i << endl;
        print_prio(q);
        if(i%2!=0)
        {
        	cout << "Pairing " << i << " pilot with someone\n";
            str x=q.top();
            s=s-(x.a-x.b);
            q.pop();
        }
    }
    cout<<s;
}