#include <bits/stdc++.h>

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;

    cin >> n >> m;

    /*
    if (n == 1) {

        int xr, yr;

        cin >> xr >> yr;

        int x, y;

        for (int i = 0 ; i < m ; i++) {

            cin >> x >> y;

        }

        return 0;

    }
    */

    int x, y;

    for (int i = 0 ; i < n ; i++) {

        cin >> x >> y;

    }

    for (int i = 0 ; i < m ; i++) {

        cin >> x >> y;

    }

    if (x%n == 0) {

        cout << x * y << "\n";
        cout << n * n << "\n";

        for (int i = 0 ; i < n ; i++) {

            for (int j = 0 ; j < m ; j++) {

                cout << i+1 << " " << j+1 << " " << x/n << "\n";

            }

        }

        return 0;
    }

    cout << n * x << "\n";
    cout << n * n << "\n";

    for (int i = 0 ; i < n ; i++) {

        for (int j = 0 ; j < m; j++) {

            if (i == j) { cout << i+1 << " " << j+1 << " " << x/n + x%n << "\n"; continue; }
             cout << i+1 << " " << j+1 << " " << x/n << "\n";

        }

    }

    return 0;

}