#include <cstdio>
#include <algorithm>
#include <sstream>

using namespace std;

#include "random.h"

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

#define GET(s, a) { stringstream ss(s); ss >> (a); }

int main( int argc, char *argv[] )
{
  if (argc < 5)
  {
    puts("Usage: <seed for random> <n> <m> <w>");
    puts("  [seed == 0] => Time()");
    return 1;
  }

  int seed = atoi(argv[1]);
  int n = atoi(argv[2]);
  int m = atoi(argv[3]);
  int c = atoi(argv[4]);

  if (seed == 0)
    seed = Time(), fprintf(stderr, "seed = %d\n", seed);
  initrand(seed);

  printf("%d %d\n", n, m);
  forn(i, m)
    printf("%d %d %d\n", R(0, n - 1), R(0, n - 1), R(0, c));
  return 0;
}