#include <cstdio>
#include <cstring>
#include <cassert>
#include <set>
#include <algorithm>

using namespace std;

#define MAXT 1000
#define MAXN 5000
#define INF (MAXN + 1)
#define MAXR ((int)1e9)
int F[MAXN + 1][MAXN + 1];

int main() {
  int n, a, b, t, nsum = 0;
  
  scanf("%d", &t);
  assert(1 <= t && t <= MAXT);
  for (int tn = 0; tn < t; tn++) {
  
    scanf("%d%d%d", &n, &a, &b);
    nsum += n;
    assert(1 <= n && n <= MAXN && nsum <= MAXN && 1 <= a && a <= MAXR && 1 <= b && b <= MAXR);
  
    vector <pair <int, int>> S;
    for (int i = 0; i < n; i++) {
      int s, r;
      scanf("%d%d", &s, &r);
      assert(1 <= s && s <= a && 1 <= r && r <= b);
      S.push_back(make_pair(s, r));
    }
    sort(S.begin(), S.end());
    for (int i = 1; i < (int)S.size(); i++) assert(S[i - 1].first != S[i].first || S[i - 1].second != S[i].second);
  //memset(F, 1, sizeof(F)); // ~17e6
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++) 
        F[i][j] = INF;
    F[0][0] = 0;
    int p = 0, q = 0;
    while (q < n) {
      int r = n;
      ++p;
      for (int i = q + 1; i < n; i++) if (S[i].first != S[q].first) { r = i; break; }
      for (int j = 0; j <= n; j++)
        if (F[p - 1][j] < INF) {
          assert (j + (r - q) <= MAXN);
          F[p][j + r - q] = min(F[p][j + r - q], F[p - 1][j]);
          int rt = 0; //required to take
          for (int s = q + 1; s <= r; s++) {
            int c = s - q + rt; //number of cards left in the suit, including those we taken to cover previous ones
            int z = S[s - 1].second - 2 * (c - 1); //imagine c = 2: we need 3 -> 1, 4 -> 2; 5 -> 3 (then divide by 2)
            rt += z <= 1 ? 0 : z / 2; //number of cards to take in the suit to cover current card
            int x = min(F[p - 1][j] + rt, INF);
            F[p][j + r - s] = min(F[p][j + r - s], x);
            //if (x > INF) break; //think about test which will TL if not done
          }
        }
      q = r;
    }
    assert(p <= n);
  /*for (int i = 0; i <= 2; i++)
    for (int j = 0; j <= 4; j++)
      printf("%d %d %d\n", i, j, F[i][j]);*/
    for (int i = 0; i <= n; i++) if (F[p][i] <= i) {
      printf("%d\n", i);
      break;
    }
  }
  //assert(false);
}
