// This software is free for use by anyone for any purpose without restriction.
// The software is provided as is, with all faults, defects and errors,
// and without warranty of any kind, either expressed or implied.
// 
// Validator code. Specification is compatible with standard validator
// such as check_float_abs_e4.c.
// Please see "Usage" how to use this code.

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>

typedef int64_t ll;

struct IP {
  ll x, y;
  IP() {}
  IP(ll x, ll y) : x(x), y(y) {}
  IP operator+(const IP &rhs) const { return IP(x + rhs.x, y + rhs.y); }
  IP operator-(const IP &rhs) const { return IP(x - rhs.x, y - rhs.y); }
  IP operator-() const { return IP(0, 0) - *this; }
  bool operator<(const IP &rhs) const {
    return (x != rhs.x) ? x < rhs.x : y < rhs.y;
  }
};

ll dot(IP p1, IP p2) { return p1.x * p2.x + p1.y * p2.y; }
ll cross(IP p1, IP p2) { return p1.x * p2.y - p1.y * p2.x; }
ll norm(IP a) { return a.x * a.x + a.y * a.y; }
int ccw(IP a, IP b, IP c) {
  b = b - a; c = c - a;
  if (cross(b, c) > 0)   return +1;    // counter clockwise
  if (cross(b, c) < 0)   return -1;    // clockwise
  if (dot(b, c) < 0)     return +2;    // c--a--b on line
  if (norm(b) < norm(c)) return -2;    // a--b--c on line
  return 0;                            // a--c--b
}

// -1 => no intersection
// 0  => overlap (parallel)
// 1  => has intersection and not parallel but is intersecting at edge
// 2  => has intersection
int isis_ss(IP s0, IP s1, IP t0, IP t1) {
  int c00 = ccw(s0, s1, t0), c01 = ccw(s0, s1, t1),
      c10 = ccw(t0, t1, s0), c11 = ccw(t0, t1, s1);
  if (c00*c01 == -1 && c10*c11 == -1) return 2;
  if (c00*c01 == 1 || c10*c11 == 1) return -1;

  bool para = (cross(s1-s0, t1-t0) == 0.0);
  int edge = abs(c00*c01*c10*c11);
  if (para) {
    if (edge == 16) return -1;
    else
      return 0;
  }
  return 1;
}

const int EXIT_AC = 42;
const int EXIT_WA = 43;

int main(int argc, char** argv) {
  if (argc < 4) {
    puts("Usage: %s [Input file] [IGNORED] feedback_dir");
    return -1;
  }

  FILE* fi = fopen(argv[1], "r");
  FILE* fo = stdin;
  FILE* jm = fopen((std::string(argv[3]) + "/judgemessage.txt").c_str(), "w");
  FILE* dp = fopen((std::string(argv[3]) + "/diffposition.txt").c_str(), "w");
  if (!fi || !fo || !jm || !dp) {
    puts("File error.");
    return -1;
  }

  int T;
  fscanf(fi, "%d", &T);
  for (int testcase = 0; testcase < T; ++testcase) {
    int X, Y;
    fscanf(fi, "%d%d", &X, &Y);

    // actually, I don't care white spaces
    int n;
    if (fscanf(fo, "%d", &n) != 1) {
      fprintf(jm, "Error: The output of the %d-th (0-indexed) test case is invalid.\n", testcase);
      return EXIT_WA;
    }

    // check if parameter is valid
    if (n < 3 || n > 4) {
      fprintf(jm, "Error: n should be either 3 or 4 in the %d-th (0-indexed) test case. n=%d is found.\n", testcase, n);
      return EXIT_WA;
    }
    std::vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i) {
      if (fscanf(fo, "%d %d", &x[i], &y[i]) != 2) {
        fprintf(jm, "Error: The output of the %d-th (0-indexed) test case is invalid.\n", testcase);
        return EXIT_WA;
      }

      if (x[i] < 0 || x[i] > X) {
        fprintf(jm, "Error: x[%d] should be between 0 and X, inclusive, in the %d-th (0-indexed) test case.\n",
               i, testcase);
        return EXIT_WA;
      }
      if (y[i] < 0 || y[i] > Y) {
        fprintf(jm, "Error: y[%d] should be between 0 and Y, inclusive, in the %d-th (0-indexed) test case.\n",
               i, testcase);
        return EXIT_WA;
      }
    }

    if (*min_element(x.begin(), x.end()) != 0) {
      fprintf(jm, "Error: There must be at least one point whose x coordinate is 0 in the %d-th (0-indexed) test case.\n",
             testcase);
      return EXIT_WA;
    }
    if (*max_element(x.begin(), x.end()) != X) {
      fprintf(jm, "Error: There must be at least one point whose x coordinate is X in the %d-th (0-indexed) test case.\n",
             testcase);
      return EXIT_WA;
    }
    if (*min_element(y.begin(), y.end()) != 0) {
      fprintf(jm, "Error: There must be at least one point whose y coordinate is 0 in the %d-th (0-indexed) test case.\n",
             testcase);
      return EXIT_WA;
    }
    if (*max_element(y.begin(), y.end()) != Y) {
      fprintf(jm, "Error: There must be at least one point whose y coordinate is Y in the %d-th (0-indexed) test case.\n",
             testcase);
      return EXIT_WA;
    }

    // check if the polygon is simple
    bool simple = 1;
    std::vector<IP> v(n);
    for (int i = 0; i < n; ++i) v[i] = IP(x[i], y[i]);
    for (int i = 0; i < n; ++i) {
      IP v0 = v[i], v1 = v[(i + 1) % n], v2 = v[(i + 2) % n];
      // if (isis_ss(v0, v1, v1, v2) != 1) simple = 0;
      int c = ccw(v0, v1, v2);
      if (c == +2 || c == 0) simple = 0;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = i + 2; j < n; ++j) {
        if (i == 0 && j == n - 1) continue;
        IP v0 = v[i], v1 = v[(i + 1) % n],
           v2 = v[j], v3 = v[(j + 1) % n];
        if (isis_ss(v0, v1, v2, v3) != -1) simple = 0;
      }
    }

    if (!simple) {
      fprintf(jm, "Error: The polygon must be simple in the %d-th (0-indexed) test case.\n",
             testcase);
      return EXIT_WA;
    }

    // check if the area is at most 25000
    ll area2 = 0;
    for (int i = 0; i < n; ++i) {
      area2 += cross(v[i], v[(i + 1) % n]);
    }
    area2 = llabs(area2);

    if (area2 > 25000 * 2) {
      fprintf(jm, "Error: The area of the polygon must be at most 25,000 in the %d-th (0-indexed) test case."
             "The area of the output is %lld/2.\n",
             testcase, area2);
      return EXIT_WA;
    }
  }

  fclose(fi);
  fclose(fo);
  fclose(jm);
  fclose(dp);
  return EXIT_AC;
}
