#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int n,m,a[50005],b[50005],c[50005],d[50005];
void set1(){
    int res[50005],sum=0,br=0,raz=0;
    for (int i=1;i<=m;i++){
        res[i]=c[i];
        sum+=c[i];
    }
    cout << sum << "\n";
    if (sum<b[1]){
        raz=b[1]-sum;
        int k=1;
        while(raz>0){
                cout << raz << "\n";
            if (raz>=d[k]){
                res[k]=d[k];
                raz-=d[k]-c[k];
            }
            else {
                if (raz>=c[k]){
                    res[k]=raz;
                    raz-=raz;
                }
                else {
                    continue;
                }
            }
            k++;
        }
    }
    cout << sum << "\n" << br << "\n";
    for (int i=1;i<=m;i++){
        cout << "1 " << i  << " " << res[i] << "\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> a[i] >> b[i];
    }
    for (int i=1;i<=m;i++){
        cin >> c[i] >> d[i];
    }
    if (n==1) set1();
    else cout << "1\n1\n1 1 1\n";
    return 0;
}