#include<stdio.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
int dis;
int fuel;
};
node s[100005];
bool cmp(struct node a, struct node b)
{
return a.dis < b.dis;
}
queue<int>q;
int main()
{
int n ;
cin >>n;
int l;
int p;
for(int i =0 ; i < n ;i++)
{
scanf("%d %d", &s[i].dis,&s[i].fuel);
}
scanf("%d %d",&ll,&p);
sort(s,s+n,cmp);
int l = ll;
for(int i =0 ; i < n ; i++)
{
while(l-s[i].dis<0)
{
if(!q.empty())
{
puts("-1");
}
tank += q.top();
que.
}
tank -=s[i].dis;
pos = s[i].dis;
q.push(s[i].fuel);
}
for(int i =0 ; i < n ;i++)
{
printf("%d %d\n", s[i].dis,s[i].fuel);
}
}