#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 start;
    ll end;
    ll id;

    Limit(ll _start, ll _end, ll _id) {
        start = _start;
        end = _end;
        id = _id;
    }
};

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

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;
    set<struct Limit, greater<struct Limit>> xmin;
    set<struct Limit, greater<struct Limit>> ymin;
    loop(i, 0, n) {
        cin >> a >> b;
        ymin.insert(Limit(a, b, i));
    }
    loop(i, 0, m) {
        cin >> a >> b;
        xmin.insert(Limit(a, b, i));
    }

    ll res = 0;
    while(true) {
        struct Limit ybig = *ymin.begin();
        struct Limit xbig = *xmin.begin();

        ll newx_start = xbig.start - 1;
        ll newy_start = ybig.start - 1;
        ll newx_end = xbig.end - 1;
        ll newy_end = ybig.end - 1;

        if (newx_end >= 0 && newy_end >= 0) {
            res++;
            xmin.erase(xmin.begin());
            ymin.erase(ymin.begin());
            xmin.insert(Limit(newx_start, newx_end, xbig.id));
            ymin.insert(Limit(newy_start, newy_end, ybig.id));
            polja[make_pair(xbig.id, ybig.id)]++;
        } else {
            break;
        }
    }

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

    return 0;
}