#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
//#include <bits\stdc++.h>

using namespace std;

int main()
{
    long int  n, m, vrste [1000], kolone[10000];
    cin >> n >> m;
    for(long int  i = 1; i<=n*2; i+=2){
        cin >> vrste[i] >> vrste[i+1];
    }
    for(long int i = 1; i<= 2*m; i +=2){
        cin >> kolone[i] >> kolone[i+1];
    }
    if(n = 1){
      long long int suma = 0;
      for(long long int i = 1; i <= 2 * m; i +=2){
          suma += kolone[i];
      }
      if (suma == vrste[2]){
          cout << suma << endl;
          cout << m << endl;
          long int  pom = 1;
          for(long long k = 1; k <= m; k++){
              cout << 1 << " " << k << " " << kolone[pom] << endl;
              pom+=2;
            }
        }
        else {
            long int pom = 1;
            while(suma != vrste[2]){
                label:;
                if((suma + kolone[pom+1] - kolone[pom])> vrste[2] && (kolone[pom+1] > kolone[pom])){
                    kolone[pom+1] -= 1;
                    goto label;
                }
                //else if(suma + kolone[pom+1] - kolone[pom] < vrste[2] && kolone[pom+1] > kolone[pom]){
                //
                //}
                pom += 2;
            }
        }
    }

    return 0;
}