#include <bits/stdc++.h>

using namespace std;

int main()
{
	int N,M;
	cin>>N>>M;
	
	
	bool abjednaki=true;
	bool acnule=true;
	
	int a[N];
	int b[N];
	for(int i=0;i<N;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]!=b[i])
		{
			abjednaki=false;
		}
		if(a!=0)
		{
			acnule=false;
		}
	}
	bool cdjednaki=true;
	
	int c[M];
	int d[M];
	for(int i=0;i<M;i++)
	{
		cin>>c[i]>>d[i];
		if(c[i]!=d[i])
		{
			cdjednaki=false;
		}
		if(c!=0)
		{
			acnule=false;
		}
	}
	
	if(N==1)
	{	
		int k=0;
		int u=0;
		for(int i=0;i<M;i++)
		{
			vector<int> y;
			vector<int> n;
			if(u+d[i]>b[i])
			{	
				if(u==b[i])
				{
					cout<<u<<endl<<k<<endl;
					for(int i=0;i<k;i++)
					{
						cout<<1<<" "<<y[i]<<" "<<n[i];
					}
					return 0;
				}
				else 
				{	
						int l=b[i]-u;
						k+=1;
						u=b[i];
						y.push_back(i+1);
						n.push_back(l);
				}
				
			}
			else if(d[i]!=0)
			{
				k+=1;
				u+=d[i];
				y.push_back(i+1);
				n.push_back(d[i]);
			}
		}
	}
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}