#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, m, bk, bp, rk=0, pk=0, ok;
    cin>>n>>m;
    int tk[m];
    int np[m];
    int minr, maxr;
    vector<pair<int, int>> mk(m);
    cin>>minr>>maxr;
    for(int i=0; i<m; i++){
        cin>>mk[i].first>>mk[i].second;
        tk[i]=mk[i].first;
        rk+=mk[i].first;
        if(mk[i].first!=0) pk++;
        
        }

    if(rk==maxr){
        cout<<rk<<endl;
        cout<<pk<<endl;
        int i=0;
        while(pk>0){
            if(tk[i]!=0){
                cout<<1<<" "<<i<<" "<<tk[i]<<endl;
            pk--;
            }
            i++;
        
        }

    return 0;
    }
    ok = maxr- rk;
    for(int i=0; i<m; i++){
            if(ok>mk[i].second){
            ok-=mk[i].second - tk[i];
            rk +=mk[i].second - tk[i];
            tk[i]=mk[i].second;
            if(mk[i].first ==0) pk++;
            }
            
            else{
                if(mk[i].first ==0) pk++;
            tk[i]+= ok;
            ok=0;
            rk= maxr;
            break;
            }
    }
    
    cout<<rk<<endl;
        cout<<pk<<endl;
        int i=0;
        while(pk>0){
            if(tk[i]!=0){
                cout<<1<<" "<<i<<" "<<tk[i]<<endl;
            pk--;
            }
            i++;

         
           
    }
     return 0;}