#include <bits/stdc++.h>

#define ll long long
#define loop(i, s, e) for(ll i = s; i < e; i++)

using namespace std;

struct Limit {
    ll lim;
    ll id;

    Limit(ll _lim, ll _id) {
        lim = _lim;
        id = _id;
    }
};

bool operator>(const Limit &l1, const Limit &l2) {
    return l1.lim > l2.lim;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll n, m, a, b;
    cin >> n >> m;

    map<pair<ll, ll>, ll> polja;
    multiset<struct Limit, greater<struct Limit>> xmin;
    multiset<struct Limit, greater<struct Limit>> ymin;
    loop(i, 0, n) {
        cin >> a >> b;
        ymin.insert(Limit(a, i));
    }
    loop(i, 0, m) {
        cin >> a >> b;
        xmin.insert(Limit(a, i));
    }

    ll res = 0;
    loop(i, 0, 20) {
        struct Limit ybig = *ymin.begin();
        struct Limit xbig = *xmin.begin();

        ll nxbig = xbig.lim - 1;
        ll nybig = ybig.lim - 1;

        if (nybig >= 0 && nxbig >= 0) {
            res++;
            xmin.erase(xmin.begin());
            ymin.erase(ymin.begin());
            xmin.insert(Limit(nxbig, xbig.id));
            ymin.insert(Limit(nybig, ybig.id));
            polja[make_pair(xbig.id, ybig.id)]++;
        }
    }

    cout << res << '\n';
    cout << polja.size() << '\n';
    for(auto x : polja) {
        cout << x.first.first + 1 << ' ' << x.first.second + 1 << ' ' << x.second << '\n';
    }

    return 0;
}