#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> PL;

ll n, q, h, s;
map<ll, set <ll> > mp;
set<ll>::iterator it;

int main(){
	cin >> n >> q;
	REP(i, q){
		cin >> h >> s;
		if (mp.empty()){
			mp[s].insert(h);
			cout << h << " " << s << endl;
			continue;
		}
		REP(i, 101){
			it = mp[i].find(h);
			if (mp[i].find(h) != mp[i].end()){
				mp[i + s].insert(h);
				mp[i].erase(it);
				break;
			}
			if (i == 100){
				mp[s].insert(h);
			}
		}
		for (int i = 100; i >= 0;i--){
			if (!mp[i].empty()){
				it = mp[i].begin();
				cout << *it << " " << i << endl;
				break;
			}
		}
	}
}