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

namespace ConsoleApp3
{
    internal class Program
    {
        static void f1(int a , int b , int[] c , int[] d , int n)
        {
            int[,] matrica = new int[n,3];
            int s = 0, br = 0 , s2 = 0 ;
            for (int i = 0; i < n; i++) {
                if (a > c[i]){
                    matrica[i, 0] = 1;
                    matrica[i, 1] = i + 1;
                    matrica[i, 2] = a;
                    br++;
                    s2 += a;
                }
                else if (c[i]!=0)
                {
                    matrica[i, 0] = 1;
                    matrica[i, 1] = i + 1;
                    matrica[i, 2] = c[i];
                    br++;
                    s2 += c[i];
                }

                if (b < d[i])
                    s += b;
                else
                    s += d[i];
            }
            Console.WriteLine(s);
            Console.WriteLine(s2);
            for (int i = 0; i < br; i++) {
                Console.Write(matrica[i , 0]);Console.Write(' ');
                Console.Write(matrica[i, 1]);Console.Write(' ');
                Console.Write(matrica[i, 2]);Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            int i;
            var s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int[] a = new int[n], b = new int[n], c = new int[m], d = new int[m];
            int[,] matrica = new int[n, m];
            for (i = 0; i < n; i++) {
                s = Console.ReadLine().Split();
                a[i] = int.Parse(s[0]);
                b[i] = int.Parse(s[1]);
            }
            for (i = 0; i < m; i++) {
                s = Console.ReadLine().Split();
                c[i] = int.Parse(s[0]);
                d[i] = int.Parse(s[1]);
            }

            if (n == 1) {
                f1(a[0], b[0], c, d, m);
            }
            Console.ReadLine();
        }
    }
}