#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,B[500005],A[500005],C[500005],sum,sum2;
int main(){
  scanf("%d %d", &n, &m);
  scanf("%d %d", &a, &b);
  for(int i=1; i<=m; i++){
    scanf("%d %d", &A[i], &B[i]);
    sum2+=B[i];
  }
  for(int i=1; i<=m; i++){
    C[i]=A[i];
    sum+=A[i];
  }
  int mesto=1;
  while(sum-A[mesto]+B[mesto]<b){
    C[mesto]=B[mesto];
    sum=sum-A[mesto]+B[mesto];
    mesto++;
  }
  C[mesto]+=b-sum;
  if(sum2>=b) printf("%d\n", b);
  else printf("%d\n", sum2);
  printf("%d\n", m);
  for(int i=1; i<=m; i++){
    cout << 1 << " " << i << " " << C[i] << "\n";
  }
  return 0;
}