#include <cstdio>
#include <cassert>
#include <algorithm>

using namespace std;

int n, a, b;

int S[20][20], X[20][20];

int rec(int ca, int cb, int ad, int rm) {
  if (cb >= b) return rec(ca + 1, 0, ad, rm);
  if (ca >= a) {
    if (ad != rm) return n;
    for (int i = 0; i < a; i++) {
      int cnt = 0;
      for (int j = 0; j < b; j++) {
        if (S[i][j] ^ X[i][j]) {
          if (j > 2 * cnt) return n;
          ++cnt;
        }
      }
    }
    return ad;
  }
  X[ca][cb] = 0;
  int v1 = rec(ca, cb + 1, ad, rm);
  X[ca][cb] = 1;
  int v2 = rec(ca, cb + 1, ad + 1 - S[ca][cb], rm + S[ca][cb]);
  return min(v1, v2);
}

int main() {
  int t;
  scanf("%d", &t);
  for (int tn = 0; tn < t; tn++) {
    scanf("%d%d%d", &n, &a, &b);
    assert(a <= 20 && b <= 20 && a * b <= 35);

    for (int x = 0; x < a; x++)
      for (int y = 0; y < b; y++)
        S[x][y] = 0;

    for (int i = 0; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      S[x - 1][y - 1] = 1;
    }
    printf("%d\n", rec(0, 0, 0, 0));
  }
}
