#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define P pair<long,long>
using namespace std;
bool cmp(const P& p,const P& q){
	if(p.second!=q.second) return p.second>q.second;
	return p.first<q.first;
}
int main() {
	long n,q ; cin >> n >> q ;
	P ans; long a[10000001]={0}; bool flag[1000001]={0};
	vector<P> v; vector<P>::iterator vp;
	for(long i=0;i<q;i++){
		long tmp,TMP; cin >> tmp >> TMP;
		if(!flag[tmp]){
			v.push_back(P(tmp,TMP)); a[tmp]=TMP; flag[tmp]=true;
			if(ans.second<TMP) ans.second=TMP,ans.first=tmp;
			else if(ans.second==TMP && ans.first>tmp) ans.first=tmp;
		} else {
			vp=find(v.begin(),v.end(),P(tmp,a[tmp])); vp->second+=TMP; a[tmp]+=TMP;
			if(ans.second<vp->second) ans.second=vp->second, ans.first=vp->first;
			else if(ans.second==vp->second && ans.first>vp->first) ans.first=vp->first;
			else {sort(v.begin(),v.end(),cmp); ans.first=v[0].first,ans.second=v[0].second;}
		}
		if(!i) ans.first=tmp, ans.second=TMP;
		cout << ans.first << ' ' << ans.second << '\n' ;
	}
}