#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,y,z,pos,l,r;
LL Ans,x;
int a[N],b[N];
char c[N];

IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

struct Segtree{
	struct Tree{
		int l,r;
		LL d,lz;
	}t[N*4];

	IL void Maketree(int x,int low,int high){
		int mid=(low+high)>>1;
		t[x].l=low;	t[x].r=high;
		if (low==high){t[x].d=a[low];	return;}
		Maketree(l(x),low,mid);	Maketree(r(x),mid+1,high);
		t[x].d=Min(t[l(x)].d,t[r(x)].d);
	}

	IL void Push(int x){
		LL p=t[x].lz;
		t[l(x)].d+=p;	t[r(x)].d+=p;
		t[l(x)].lz+=p;	t[r(x)].lz+=p;
		t[x].lz=0;
	}

	IL void Add(int x,int low,int high,LL val){
		reg int mid=(t[x].l+t[x].r)>>1;
		if (t[x].l==low && t[x].r==high){
			t[x].d+=val;	t[x].lz+=val;
			return;
		}
		if (t[x].lz) Push(x);
		if (high<=mid)	Add(l(x),low,high,val);
		else if (low>mid)	Add(r(x),low,high,val);
		else Add(l(x),low,mid,val),Add(r(x),mid+1,high,val);
		t[x].d=Min(t[l(x)].d,t[r(x)].d);
	}

	IL LL Query(int x,int low,int high){
		reg int mid=(t[x].l+t[x].r)>>1;
		if (t[x].l==low && t[x].r==high)	return t[x].d;
		if (t[x].lz) Push(x);
		if (high<=mid)	return Query(l(x),low,high);
		else if (low>mid)	return Query(r(x),low,high);
		else return Min(Query(l(x),low,mid),Query(r(x),mid+1,high));
	}
}T1,T2;

struct Tree{
	int l,r;
	LL d,lz;
}t[N*4];

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	m=read();
	T1.Maketree(1,1,m);
	for (i=1;i<=m;i++)	a[i]=-i;
	T2.Maketree(1,1,m);
	for (i=1;i<=n;i++){
		l=read();	r=read();
		
		if (r<m){
			Ans=T2.Query(1,1,r);	x=T1.Query(1,r+1,r+1);
			if (Ans+r+1<x)	T1.Add(1,r+1,r+1,Ans+r+1-x),T2.Add(1,r+1,r+1,Ans+r+1-x);
		}

		T1.Add(1,l,r,INF);	T2.Add(1,l,r,INF);
		T1.Add(1,1,m,1);	T2.Add(1,1,m,1);
		
		Ans=T1.Query(1,1,m);
		if (Ans>=INF)	puts("-1");
		else printf("%lld\n",Ans);
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int vis[1010][1010];
inline vector<pair<int,int> > getdistant(int n,int D1,bool hasret=true)
{
	int cnt[2]={0,0};
	vector<pair<int,int> > ret,trans;
	for(int i=0;i<n;i++)
	{
		int v=round(sqrt(D1-i*i));
		if(v*v+i*i==D1)trans.push_back(make_pair(i,v)),trans.push_back(make_pair(i,-v)),trans.push_back(make_pair(-i,v)),trans.push_back(make_pair(-i,-v));
	}
	memset(vis,255,sizeof(vis));
	queue<pair<int,int> > q;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(vis[i][j]==-1)
			{
				// puts("----");
				q.push(make_pair(i,j));
				vis[i][j]=0;
				while(!q.empty())
				{
					pair<int,int> fr=q.front();q.pop();
					// printf("%d %d\n",fr.first,fr.second);
					for(auto &x:trans)
					{
						int nx=fr.first+x.first,ny=fr.second+x.second;
						if(nx>=0&&nx<n&&ny>=0&&ny<n&&vis[nx][ny]==-1)
						{
							vis[nx][ny]=vis[fr.first][fr.second]^1;
							q.push(make_pair(nx,ny));
						}
					}
				}
			}
		}
	}
	if(!hasret)return ret;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cnt[vis[i][j]]++;
		}
	}
	if(cnt[0]>cnt[1])
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]==0)ret.push_back(make_pair(i,j));
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]==1)ret.push_back(make_pair(i,j));
			}
		}
	}
	return ret;
}
int vis2[1010][1010];
inline vector<pair<int,int> > solve(int n,int d1,int d2)
{
	vector<pair<int,int> > ret;
	if(n==1)
	{
		ret.push_back(make_pair(0,0));
		return ret;
	}
	if(d1%4&&d2%4)
	{
		for(int i=0;i<n;i+=2)
		{
			for(int j=0;j<n;j+=2)
			{
				ret.push_back(make_pair(i,j));
			}
		}
		return ret;
	}
	if(d2%4==0)swap(d1,d2);
	if(d2%4)
	{
		auto p=getdistant(n/2,d1/4);
		if(d2%4==2)
		{
			for(auto &x:p)
			{
				ret.push_back(make_pair(x.first*2,x.second*2));
				ret.push_back(make_pair(x.first*2,x.second*2+1));
			}
		}
		else
		{
			for(auto &x:p)
			{
				ret.push_back(make_pair(x.first*2,x.second*2));
				ret.push_back(make_pair(x.first*2+1,x.second*2+1));
			}
		}
		return ret;
	}
	else
	{
		getdistant(n,d2,0);
		memcpy(vis2,vis,sizeof(vis));
		getdistant(n,d1,0);
		int cnt[4]={0,0,0,0};
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cnt[vis[i][j]*2+vis2[i][j]]++;
			}
		}
		int mx=0;
		for(int i=1;i<=3;i++)if(cnt[i]>cnt[mx])mx=i;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]*2+vis2[i][j]==mx)ret.push_back(make_pair(i,j));
			}
		}
		return ret;
	}
}
int n,D1,D2;
int main()
{
	scanf("%d%d%d",&n,&D1,&D2);
	auto ans=solve(n<<1,D1,D2);
	ans.resize(n*n);
	for(auto &p:ans)printf("%d %d\n",p.first,p.second);
	return 0;
}