#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int ai, bi;
    cin >> ai >> bi;
    vector<pair<int, int>> v;
    v.push_back(make_pair(0, 0));
    vector<int> res;
    int zbir = 0;
    res.push_back(0);
    for (int j = 1; j <= m; j++){
        int cj, dj;
        cin >> cj >> dj;
        v.push_back(make_pair(cj, dj));
        res.push_back(cj);
        zbir += cj;
    }
        
    int k = 0;
    
    int i = 1;
    while (zbir <= bi){
        if (v[i].second - v[i].first <= bi - zbir){
            res[i] = v[i].second;
            zbir += v[i].second - v[i].first;
            k++;}
        else{
            res[i] += bi - zbir;
            k++;
            break;}
        i++;}
    
    cout << zbir << endl;
    cout << k << endl;
    for (int i = 1; i <= k; i++){
        cout << "1" << " " << i << " " << res[i] << endl;
    }
    
    
    return 0;
}