using System;
class krompir
{
    static void Main()
    {
        string[] st = Console.ReadLine().Split();
        int n = int.Parse(st[0]);
        int m = int.Parse(st[1]);
        int[] b = new int[m];
        int[] t = new int[m];
        int max = 0;
        for (int i = 0; i < n; i++)
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int q = int.Parse(s[1]);
            max = q;
        }
        int u = 0;
        int k = 0;
        for (int i = 0; i < m; i++)
        {
            string[] s = Console.ReadLine().Split();
            int c = int.Parse(s[0]);
            int d = int.Parse(s[1]);
            if (d != 0 && u < max)
            {
                if (c == d)
                {
                    if ((u + c) <= max)
                    {
                        b[k] = c;
                        u += c;
                        t[k] = i;
                        k++;
                    }
                }
                else
                {
                    if ((u + d > max))
                    {
                        if (max - u != 0)
                        {
                            b[k] = max - u;
                            u += b[k];
                            t[k] = i;
                            k++;
                        }
                    }
                    else
                    {
                        b[k] = d;
                        t[k] = i;
                        k++;
                    }
                }
            }
        }
        Console.WriteLine(u);
        Console.WriteLine(k);
        for (int i = 0; i < k; i++)
        {
            Console.WriteLine("1" + " " + (t[i] + 1) + " " + b[i]);
        }
        int h = int.Parse(Console.ReadLine());
    }
}