#include "testlib.h"

using namespace std;

int main(int argc, char **argv) {
  registerGen(argc, argv, 1);

  int t = opt<int>("t");
  int n = opt<int>("n");
  int p = opt<int>("p");
  int c = opt<int>("c");
  int d = opt<int>("d");

  auto up = [](int x, int dx, int c) {
    if (dx == 0) return 100000;
    if (dx > 0) return (c - x) / dx;
    return (x + c) / -dx;
  };

  auto out = [&](int x, int y, int dx, int dy, int minf) {
    int r = rnd.next(minf, min(up(x, dx, c), up(y, dy, c)));
    int l = -rnd.next(0, min(up(x, -dx, c), up(y, -dy, c)));
    printf("%d %d %d %d\n", x + l * dx, y + l * dy, x + r * dx, y + r * dy);
  };

  printf("%d\n", t);
  for (int i = 0; i < t; i++) {
    printf("%d\n", n);
    vector<pair<int, int>> pt;
    for (int i = 0; i < p; i++) {
      int x = rnd.next(-c/3, c/3);
      int y = rnd.next(-c/3, c/3);
      pt.emplace_back(x, y);
    }
    for (int i = 0; i < n; i++) {
      if (rnd.next(0, 100) < d) {
        auto a = pt[rnd.next(p)];
        auto b = pt[rnd.next(p)];
        while (a == b) {
          b = pt[rnd.next(p)];
        }
        auto [x1, y1] = a;
        int dx = b.first - x1;
        int dy = b.second - y1;
        int g = __gcd(abs(dx), abs(dy));
        dx /= g;
        dy /= g;
        out(x1, y1, dx, dy, g);
      } else {
        auto [x1, y1] = pt[rnd.next(p)];
        int dx = rnd.next(-c/3, c/3);
        int dy = rnd.next(-c/3, c/3);
        out(x1, y1, dx, dy, 1);
      }
    }
  }
}
