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

namespace ConsoleApp3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]), 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 zbira = 0, zbirb = 0, zbirc = 0, zbird = 0;
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                a[i] = int.Parse(s[0]);
                zbira += a[i];
                b[i] = int.Parse(s[1]);
                zbirb += b[i];
            }
            for (int i = 0; i < m; i++)
            {
                s = Console.ReadLine().Split();
                c[i] = int.Parse(s[0]);
                zbirc += c[i];
                d[i] = int.Parse(s[1]);
                zbird += d[i];
            }
            if (n == 1)
            {
                int br = Math.Min(zbird, zbira);
                Console.WriteLine(br);
                for (int i = 0; i < m; i++)
                {
                    if (br <= 0) break;
                    Console.WriteLine("1 " + i + " " + Math.Min(d[i], br));
                    br -= d[i];
                }
            }
        }
    }
}