#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];
pll e[maxn];
map<pll,ll> cnt;
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];
    ll sa = 0,sc = 0,sb = 0,sd = 0;
    for(ll i = 1;i<=n;i++) sa+=a[i];
    for(ll i = 1;i<=n;i++) sb+=b[i];
    for(ll i = 1;i<=m;i++) sc+=c[i];
    for(ll i = 1;i<=m;i++) sd+=d[i];
    if(sa==0&&sc==0){
        ll j = 1;
        for(ll i = 1;i<=n;i++){
            while(b[i]>d[j]&&j<=m){
                if(d[j]==0){j++; continue;}
                cnt[{i,j}] = d[j];
                b[i]-=d[j];
                j++;
            }
            if(j==m+1) break;
            cnt[{i,j}] = b[i];
            d[j]-=b[i];
        }
        cout<<sz(cnt)<<endl;
        for(auto it : cnt){
            pll p = it.fi;
            ll x = p.fi;
            ll y = p.sc;
            cout<<x<< " "<<y<< " "<<it.sc<<endl;
        }
    }
    return 0;
}