#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a[50001], b[50001], c[50001], d[50001];
ll n, m;
ll rez;

ll maksi;


int main()
{
    cin >> n >> m;
    rez = 0;
    for (int i=0; i<n; ++i) {
        cin >> a[i] >> b[i];

    }
    for (int i=0; i<m; ++i) {
        cin >> c[i] >> d[i];

    }
    if (n==1){
        maksi = 0;
        for (ll i=0; i<m; i++) maksi += d[i];
        if (b[0]>=maksi){
            cout << maksi << endl;
            for (ll i=0; i<m; i++) {
                if (d[i]>0) cout << "1 " << i+1 << " " << d[i] << endl;
            }
            return 0;
        }
        else{
            ll razlika = maksi - b[0];
            cout << b[0] << endl;
            for (ll i=0; i<m; i++){
                if (razlika>0){
                    if(max (c[i], d[i]-razlika)>0)cout << "1 " << i+1 << " " << max (c[i], d[i]-razlika) << endl;
                    if (razlika > d[i]-c[i]) razlika -= d[i]-c[i];
                    else razlika = 0;
                }
                else if(d[i]>0) cout << "1 " << i+1 << " " << d[i] << endl;
            }
        }
    }

    return 0;
}