int connections[15][2] = {
    {0, 2}, {0, 3}, {0, 4}, 
    {1, 3}, {1, 4}, {1, 5}, 
    {6, 2}, {6, 3}, {6, 4}, 
    {7, 3}, {7, 4}, {7, 5}, 
    {2, 3}, {3, 4}, {4, 5}, 
};

int pegs[8];
int num = 0;

bool valid() {
    int i;
    for (i = 0; i < 15; i++) {
        if (abs(pegs[connections[i][0]] - pegs[connections[i][1]]) == 1) {
            return false;
        }
    }
    return true;
}

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

void printSolution() {
    printf(, num++);
    printf(,  pegs[0], pegs[1]);
    printf(, pegs[2], pegs[3], pegs[4], pegs[5]);
    printf(,  pegs[6], pegs[7]);
    printf();
}

void solution(int le, int ri) {
    if (le == ri) {
        if (valid()) {
            printSolution();
        }
    } else {
        int i;
        for (i = le; i <= ri; i++) {
            swap(pegs + le, pegs + i);
            solution(le + 1, ri);
            swap(pegs + le, pegs + i);
        }
    }
}

int main() {
    int i;
    for (i = 0; i < 8; i++) {
        pegs[i] = i + 1;
    }

    solution(0, 8 - 1);
    return 0;
}