#include <cstdio>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
#define MP make_pair<int,int>
int q,a,v,score[1000001];
pii P;
priority_queue<pii> Q;
int main(){
  scanf("%d%d",&q,&q);
  Q.push(MP(0,-1));
  while(q--){
    scanf("%d%d",&a,&v);
    score[a] += v;
    Q.push(MP(score[a],-a));
    while(true){
      P = Q.top();
      if(score[-P.second]!=P.first)Q.pop();
      else{
        printf("%d %d\n",-P.second,P.first);
        break;
      }
    }
  }
  return 0;
}