using System;

namespace ConsoleApp1
{
    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[] a = new int[n];
            int[] b = new int[n];
            int[] c = new int[m];
            int[] d = new int[m];
            int[,] mat = new int[n,m];
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                a[i] = int.Parse(s[0]);
                b[i] = int.Parse(s[1]);
            }
            for (int i = 0; i < m; i++)
            {
                s = Console.ReadLine().Split();
                c[i] = int.Parse(s[0]);
                d[i] = int.Parse(s[1]);
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (Math.Min(b[i], d[j]) >= Math.Max(a[i], c[j]))
                    {
                        Console.WriteLine((i + 1) + " " + (j + 1) + " " + Math.Min(b[i], d[j]));
                    }
                }
            }
        }
    }
}