#include<bits/stdc++.h>
using namespace std;
long long n,m,maks,pocetaki[50005],brp,pocetakj[50005],suma,kraji[50005],krajj[50005],bri[50005],brj[50005];
 long long mp[2500][2500];
int main(){
   scanf("%d",&n);
   scanf("%d",&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&pocetaki[i]);
        scanf("%d",&kraji[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&pocetakj[i]);
        scanf("%d",&krajj[i]);
    }
    for(int i=1;i<=n;i++){
        suma+=kraji[i];
    }
    while(maks!=suma){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if((bri[i]<kraji[i]) and (brj[j]<krajj[j])){
                mp[i][j]++;
                bri[i]++;
                brj[j]++;
                maks++;
        }
        }
        }
    }

        /*for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(brj[j]<pocetakj[j]){
                mp[i][j-1]--;
                mp[i][j]++;
                brj[j]++;
            }
        }
        }*/
        for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
           if(mp[i][j]!=0)
            brp++;
        }
        }
        printf("%d",suma);
        cout<<"\n";
        printf("%d",brp);
        cout<<"\n";

        for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(mp[i][j]!=0){
                cout<<i<<" "<<j<<" "<<mp[i][j]<<"\n";
            }
        }
        }
return 0;
}