using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zadatak2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            int[] v = new int[n];
            int[] a = new int[n]; int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                a[i] = int.Parse(s[0]);
                b[i] = int.Parse(s[1]);
                v[i] = 0;
            }

            int[] k = new int[m];
            int[] c = new int[m]; int[] d = new int[m];
            for (int j = 0; j < m; j++)
            {
                s = Console.ReadLine().Split();
                c[j] = int.Parse(s[0]);
                d[j] = int.Parse(s[1]);
                k[j] = 0;
            }

            int[,] ij = new int[n, m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    ij[i, j] = 0;

            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    if (v[i] < b[i] && k[j] < d[j])
                        v[i] += k[j] += ij[i, j] = Math.Min(b[i], d[j]);

            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    if (ij[i, j] > 0)
                        Console.WriteLine("{0} {1} {2}", i + 1, j + 1, ij[i, j]);
        }
    }
}