#include <bits/stdc++.h>

using namespace std;

struct ogranicenja
{
    int x;
    int y;
};

int main()
{
    int n, m;
    cin >> n >> m;
    ogranicenja Oredovi[n];
    for(int i = 0; i < n; i++)
    {
        cin >> Oredovi[i].x >> Oredovi[i].y;
    }
    ogranicenja Okolone[m];
    for(int i = 0; i < m; i++)
    {
        cin >> Okolone[i].x >> Okolone[i].y;
    }

    vector<vector<int>> matrica(n, vector<int>(m, 0));
    vector<int> zbir_redova(n, 0);
    vector<int> zbir_kolona(m, 0);

    int dodato = true;
    int br_krompira = 0;
    int k = 0;
    while(dodato)
    {
        dodato = false;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(zbir_redova[i] < Oredovi[i].y && zbir_kolona[j] < Okolone[j].y)
                {
                    br_krompira++;
                    matrica[i][j]++;
                    zbir_kolona[j]++;
                    zbir_redova[i]++;
                    dodato = true;
                    if(matrica[i][j] == 1)
                    {
                        k++;
                    }
                }
            }
        }
    }
    cout << br_krompira << endl << k << endl;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(matrica[i][j] != 0)
            {
                cout << i+1 << ' ' << j+1 << ' ' << matrica[i][j] << endl;
            }
        }
    }
    return 0;
}