#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define sz(a) (ll)(a.size())
#define fi first
#define sc second
#define pll pair<ll,ll>
using namespace std;
#define maxn 50005
ll n,m;
ll a[maxn],b[maxn],c[maxn],d[maxn];
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cerr.tie(0);
    cin >> n >> m;
    for(ll i = 1;i<=n;i++) cin >> a[i] >> b[i];
    for(ll i = 1;i<=m;i++) cin >> c[i] >> d[i];
    priority_queue<pll> pqb;
    priority_queue<pll> pqd;
    for(ll i = 1;i<=n;i++) pqb.push({-b[i],i});
    for(ll i = 1;i<=m;i++) pqd.push({-d[i],i});
    map<pll,ll> cnt;
    ll ans = 0;
    while(sz(pqb)&&sz(pqd)){
        pll p = pqb.top();
        pll q = pqd.top();
        pqb.pop();
        pqd.pop();
        ll i = p.sc; ll j = p.sc;
        p.fi++;
        q.fi++;
        if(p.fi!=0) pqb.push(p);
        if(q.fi!=0) pqd.push(q);
        cnt[{i,j}]++;
        ans++;
    }
    cout<<ans<<endl;
    for(auto it : cnt){
        pll p = it.fi;
        cout<<p.fi<< " "<<p.sc<<" " <<it.sc<<endl;
    }
    return 0;
}