#include <bits/stdc++.h>

using namespace std;

int a[50005],b[50005],c[50005],d[50005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    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)
    {
        int broj;
        int mini=0,maxi=0;
        for(int i=0;i<m;i++)
        {
            mini+=c[i];
            maxi+=d[i];
        }
        broj=min(maxi,b[0]);
        cout<<broj<<endl;
        int pom=broj;
        int br=0;
        for(int i=0;i<m;i++)
        {
            if(pom<=0)
                break;
            pom-=d[i];
            br++;
        }
        cout<<br<<endl;
        for(int i=0;i<m;i++)
        {
            if(broj<=0)
                break;
            if(broj<=d[i])
            {
                cout<<1<<" "<<i+1<<" "<<broj<<endl;
                break;
            }
            cout<<1<<" "<<i+1<<" "<<d[i]<<endl;
            broj-=d[i];
        }
    }
}