#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define sc second
#define pb push_back
#define pii pair<int,int>
#define pll pair<pll,pll>
#define MAXN 50007
ll a[MAXN],b[MAXN],c[MAXN],d[MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    ll n,m; 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)
    {
        ll sumc=0,sumd=0;
        for(int i=1;i<=m;i++)
        {
            sumc+=c[i];
            sumd+=d[i];
        }
        ll mins=max(a[1],sumc);
        ll maxs=min(b[1],sumd);
        ll rez[m+1],itr=1;
        for(int i=1;i<=m;i++)
        {
            rez[i]=c[i];
            maxs-=c[i];
        }
        for(int i=1;i<=m;i++)
        {
            rez[i]+=min(maxs,d[i]-c[i]);
            maxs-=min(maxs,d[i]-c[i]);
        }
        ll k=0;
        for(int i=1;i<=m;i++)
        {
            if(rez[i]>0) k++;
        }
        cout<<k<<endl;
        for(int i=1;i<=m;i++)
        {
            if(rez[i]>0) cout<<1<<" "<<i<<" "<<rez[i]<<endl;
        }
    }
    return 0;
}