#include<bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define FORD(i, a, b) for(int i=(a); i>=(b); --i)

#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mp make_pair
#define X first
#define Y second

const int INF = 1<<29;

int N;
int P, T;
int nowP;
int complexes;

pii shapes[1005];

int dir[6][2] =  {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, -1}, {-1, 1}};

bool cmp(pii A, pii B) {
  return A.Y > B.Y;
}

set< pii > cubicles;

int main() {
  scanf("%d", &N);
  while (N--) {
    scanf("%d%d", &P, &T);
    REP(t, T) {
      int C, S;
      scanf("%d%d", &C, &S);
      shapes[t].X = C;
      shapes[t].Y = S * 6 - 2;
      cubicles.clear();
      REP(s, S) {
        int x, y;
        scanf("%d%d", &x, &y);
        cubicles.insert(mp(x, y));
        REP(k, 6) {
          if (cubicles.count(mp(x + dir[k][0], y + dir[k][1]))) shapes[t].Y -= 2;
        }
      }
//      printf("%d: oken %d\n", t, windows[t]);
    }
    complexes = 0;
    nowP = 2;
    sort(shapes, shapes + T, cmp);
    REP(t, T) {
      if (nowP + shapes[t].X * shapes[t].Y >= P) {
        complexes += (P - nowP + shapes[t].Y - 1) / shapes[t].Y;
        nowP += shapes[t].X * shapes[t].Y;
        break;
      }
      complexes += shapes[t].X;
      nowP += shapes[t].X * shapes[t].Y;
    }
//    printf("nowP %d P %d\n", nowP, P);
    if (nowP >= P) {
      printf("Je treba %d celku.\n", complexes);
    } else {
      printf("Kapacita zakladny je pouze %d lidi.\n", nowP);
    }
  }

  return 0;
}
