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


int a[50000];
int b[50000];
int c[50000];
int d[50000];
int sad[50000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    ll zbir = 0, razlika, k = 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];
        zbir += d[i];
    }
    if(n==1){
        razlika = b[0] - zbir;
        if(razlika > 0 || razlika == 0){
            cout << zbir  << "\n";
            cout << m << "\n";
                for (int j = 0;j < m; j++){
                    cout << 1 << " " << j+1 << d[j] << "\n";
                }

        }
        else{
            razlika = abs(razlika);
            cout << b[0]<<"\n";
            for (int i = 0;i < m ; i++){
                    if(razlika == 0) break;
                if(d[i]-c[i] > razlika || d[i]-c[i]==razlika){ //sadimo c[i]
                    k++;
                    sad[i] = c[i];
                    razlika -= (d[i]-c[i]);
                }
                else{//sadimo d[i] - razlika
                    k++;
                    sad[i] = d[i]-razlika;
                    razlika = 0;
                    break;
                }
            }
            cout << k << "\n";
            for (int i = 0;i < n ; i++){
                cout << 1 << i+1 << sad[i] << "\n";
            }
        }
    }
    return 0;
}