#include <bits/stdc++.h>
using namespace std;
int n,m,a[30],b[30],c[50005],d[50005],maxi,br,niz[50005],dp[50005],mini;
int main(){
  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];
    maxi+=d[i];
  }
  maxi=min(maxi,b[1]);
  cout<<maxi<<endl;
  for(int i=1;i<=m;i++){
    if(d[i]>0 and maxi>d[i]){
      br++;
      maxi-=d[i];
      niz[br]=d[i];
      dp[br]=i;
    }
    else if(d[i]>0 and maxi<d[i] and maxi!=0){
      br++;
      niz[br]=maxi;
      maxi=0;
      dp[br]=i;
    }
    else if(maxi==0)break;
  }
  cout<<br<<endl;
  for(int i=1;i<=br;i++){
    cout<<1<<" "<<dp[i]<<" "<<niz[i]<<endl;
  }
  return 0;
}