#include <bits/stdc++.h>
using namespace std;

int n, m;
int ogrRed[50005][2]; //u zadatku, a i b
int ogrKol[50005][2]; //u zadatku, c i d

//RESENJE ZA n=1

int brPolja;
int brKrompira;
int brKrompiraRed;

int polje[5005][50005];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d %d", &ogrRed[i][0], &ogrRed[i][1]);
	}
	for (int i = 1; i <= m; ++i)
	{
		scanf("%d %d", &ogrKol[i][0], &ogrKol[i][1]);
	}

	for (int i = 1; i <= n; ++i)
	{
		if (ogrRed[i][1] == 0)
		{
			continue;
		}
		brKrompiraRed = 0;
		for (int j = 1; j <= m; ++j)
		{
            if (ogrKol[j][1] == 0)
			{
				continue;
			}

			if (brKrompiraRed+ogrKol[j][0]>ogrRed[i][1])
			{
				continue;
			}
			if (brKrompiraRed + ogrKol[j][1] > ogrRed[i][1])
			{
				if (ogrKol[j][0] <= ogrRed[i][1]-brKrompiraRed)
				{
					polje[i][j] = ogrRed[i][1]-brKrompiraRed;
				}
				else
				{
					continue;
				}
			}
			else
			{
				polje[i][j] = ogrKol[j][1];
			}
			brPolja++;
			brKrompiraRed+=polje[i][j];
			if (brKrompiraRed >= ogrRed[i][1])
			{
                break;
			}
		}
		brKrompira += brKrompiraRed;
	}
	printf("%d\n", brKrompira);
	printf("%d\n", brPolja);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			if (polje[i][j] > 0)
			{
				printf("%d %d %d\n", i, j, polje[i][j]);
			}
		}
	}



	return 0;
}