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

#define ll long long

int main()
{

    int n, m;
    cin >> n >> m;
    pair<int ,int> ab[n];
    pair<int, int> cd[m];

    int i = 0;


    for(int i = 0; i < n; i++)
    {
        cin >> ab[i].first >> ab[i].second;
    }

    for(int j = 0; j < m; j++)
    {
        cin >> cd[j].first >> cd[j].second;
    }

    int stampaj[n][3];
    int k = 0;
    for(int i = 0; i < n; i++)
    {
        int x = i + 1, y = 1;
        int dodaj = ab[i].second;
        int prevMin = ab[i].second - cd[0].second;
        //int prevMinAbs = abs(ab[i].second - cd[0].second);
        for(int j = 0; j < m; j++)
        {
            if(cd[j].second - ab[i].second >= 0)
                if(cd[j].second - ab[i].second < prevMin)
                {
                    dodaj = ab[i].second;
                    prevMin = cd[j].second - ab[i].second;
                    x = i + 1;
                    y = j + 1;
                }
        }
        k += dodaj;
        //cout << x << " " << y << " " << dodaj << endl;
        stampaj[i][0] = x;
        stampaj[i][1] = y;
        stampaj[i][2] = dodaj;
    }
    cout << k << endl;
    cout << n << endl;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
            cout << stampaj[i][j] << " ";
        cout << endl;
    }

    return 0;
}