/* noncol C: read graph6 lines (n <= 32) on stdin, print those that are NOT C-colourable.
   Independent of prunecol.c / gengchi: plain DSATUR-order backtracking with bitset colour classes.
   Build: cc -O2 -o noncol noncol.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned int u32;
static int n, C;
static u32 adj[32], cls[32];  /* cls[c] = vertices with colour c */
static int col[32];

static int rec(int done) {
    if (done == n) return 1;
    /* pick uncoloured vertex with fewest available colours (DSATUR-like) */
    int best = -1, bestfree = 99;
    for (int v = 0; v < n; v++) {
        if (col[v] >= 0) continue;
        int fr = 0;
        for (int c = 0; c < C; c++) if (!(cls[c] & adj[v])) fr++;
        if (fr < bestfree) { bestfree = fr; best = v; if (fr == 0) return 0; }
    }
    int v = best, opened = 0;
    for (int c = 0; c < C; c++) {
        if (cls[c] & adj[v]) continue;
        if (!cls[c]) { if (opened) continue; opened = 1; }   /* empty classes are interchangeable */
        cls[c] |= 1u << v; col[v] = c;
        if (rec(done + 1)) return 1;
        cls[c] &= ~(1u << v); col[v] = -1;
    }
    return 0;
}

int main(int argc, char **argv) {
    C = atoi(argv[1]);
    char line[256]; long long rd = 0, out = 0;
    while (fgets(line, sizeof line, stdin)) {
        int len = strlen(line); while (len && (line[len-1] == '\n' || line[len-1] == '\r')) line[--len] = 0;
        if (!len) continue;
        rd++; n = line[0] - 63;
        memset(adj, 0, sizeof adj);
        int k = 0;
        for (int j = 1; j < n; j++) for (int i = 0; i < j; i++, k++) {
            int ch = line[1 + k / 6] - 63;
            if (ch >> (5 - k % 6) & 1) { adj[i] |= 1u << j; adj[j] |= 1u << i; }
        }
        memset(cls, 0, sizeof cls); for (int v = 0; v < n; v++) col[v] = -1;
        if (!rec(0)) { puts(line); out++; }
    }
    fprintf(stderr, "read %lld noncolourable %lld\n", rd, out);
    return 0;
}
