#include <bits/stdc++.h>
using namespace std;
struct ant {
int location;
int next;
int id;
int m;
};
vector<ant> vi;
int n, t;
bool cmp1(ant a, ant b) {
return a.id < b.id;
}
//按位置从左到右排序
bool cmp2(ant a, ant b) {
return a.location < b.location;
}
int s[]={-1,0,1};
int main() {
cin >> n >> t;
int x, y;
ant a;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
int r;
if(y==-1){
r=0;
}else{
if(y==1){
r = 2;
}
}
a = {x, y, i + 1,r};
vi.push_back(a);
}
while (t--) {
for (int i = 0; i < n; ++i) {
if (vi[i].next == 1) {
vi[i].location++;
} else {
vi[i].location--;
}
}
sort(vi.begin(), vi.end(), cmp2);
for (int i = 1; i < n; ++i) {
if (vi[i].location == vi[i - 1].location) {
//无论是+1还是-1,转向后均为0
if(vi[i].next==1||vi[i].next==-1){
vi[i].m = vi[i].next;
vi[i].next = 0;
}else{
//必然是转向成功
//如果之前是1
if(vi[i].m==1){
vi[i].next = -1;
}else{
vi[i].next = 1;
}
}
if(vi[i-1].next==1||vi[i-1].next==-1){
vi[i-1].m = vi[i-1].next;
vi[i-1].next = 0;
}else{
//必然是转向成功
//如果之前是1
if(vi[i-1].m==1){
vi[i-1].next = -1;
}else{
vi[i-1].next = 1;
}
}
swap(vi[i].id, vi[i - 1].id);
}
}
}
sort(vi.begin(), vi.end(), cmp1);
for (int i = 0; i < vi.size(); ++i) {
cout << vi[i].location << " " << vi[i].next << endl;
}
return 0;
}