#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
	int n, m, br1, br2;
	cin >> n >> m;
	vector<int> a;
	vector<int> b;
	vector<int> c;
	vector<int> d;
	
	vector<int> p;
	vector<int> q;
	
	for(int i = 0; i < n; i++){
		cin >> br1 >> br2;
		a.push_back(br1);
		b.push_back(br2);
		p.push_back(0);
	}
	for(int i = 0; i < m; i++){
		cin >> br1 >> br2;
		c.push_back(br1);
		d.push_back(br2);
		q.push_back(0);
	}
	
	
	int x = 0, k = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; i++){
			if(p[i]<b[i] && q[j]<d[j]){
				int y = min(b[i], d[j]);
				p[i]+=y;
				q[j]+=y;
				x+=y;
				k++;
				cout << i << " " << j << " " << y << endl;
			}
		}
	}
}