using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Collections;
using System.Threading;
using System.Resources;
using System.Collections.Generic;

namespace DaniloStojanovic
{
    class Program
    {
        struct indexAB
        {
            public int a;
            public int b;
        }
        struct indexCD
        {
            public int c;
            public int d;
        }
        static void pisi(int[,] matrica, int n, int m)
        {
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    if (matrica[i,j] != 0)
                    {
                        Console.Write((i+1) + " " + (j+1) + " " + matrica[i,j]);
                        Console.WriteLine();
                    }
                }
                
            }
        }
        static int suma(int[,] niz, int t, char c, int n)
        {
            int suma = 0;
            if(c == 'r')
            {
                for (int j = 0; j < n; j++)
                {
                    suma += niz[t, j];
                }
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    suma += niz[i, t];
                }
            }
            return suma;
        }
        static int[,] Krompiri(int n, indexAB[] red, int m, indexCD[] kolona)
        {
            int[,] matrica = new int[n, m];
            for(int k = 0; k < 2; k++)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (suma(matrica, i, 'r', m) + 1 <= red[i].b && suma(matrica, j, 'k', n) + 1 <= kolona[j].d)
                        {
                            matrica[i, j]++;
                        }
                        else if (suma(matrica, i, 'r', m) + 1 <= red[i].b && i > 0)
                        {
                            matrica[i - 1, j]--;
                            matrica[i, j]++;
                        }
                        else if (suma(matrica, j, 'k', n) + 1 <= kolona[j].d && j > 0)
                        {
                            matrica[i, j - 1]--;
                            matrica[i, j]++;
                        }
                    }
                }
            }
            
            return matrica;
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            indexAB[] red = new indexAB[n];

            for(int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split(' ');
                red[i].a = int.Parse(s[0]);
                red[i].b= int.Parse(s[1]);
            }
            indexCD[] kolona = new indexCD[m];
            for(int i = 0; i < m; i++)
            {
                s = Console.ReadLine().Split(' ');
                kolona[i].c = int.Parse(s[0]);
                kolona[i].d = int.Parse(s[1]);
            }
            pisi(Krompiri(n, red, m, kolona), n, m);
        }
    }
}