/*
 * This C++ program solves the n-queens problem like the Haskell code in
 * Queens.hs.
 *
 * The n-queens problem is to place n queens on an m-by-m chess board so that
 * no two queens occupy the same row, column, or diagonal.
 *
 * One possible way to make this code run faster is to tell addQueen to only
 * add a queen on the next row, not any other row.
 *
 * In Haskell, a loop body is a function.  Accordingly, in C++, a loop body is
 * an object that implements operator().  Well, we should really define it as
 * an output iterator...
 */

#include <iostream>
#include <algorithm>
#include <list>
#include <utility>

// To see final output, we define a loop body to print it.

template <typename T> class print {
public:
    void operator()(const T &t) const { std::cout << t << std::endl; }
};

// Define how to print a pair.

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

// Define how to print a list.

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::list<T> &l) {
    os << '[';
    bool first = true;
    for (typename std::list<T>::const_iterator i = l.begin();
	 i != l.end(); ++i) {
        if (first) first = false; else os << ',';
        os << *i;
    }
    return os << ']';
}

/*
 * The rest of this program follows the structure and order of Queens.hs.
 */

// We represent a board configuration by a list of queens.  We represent each
// queen as a Cartesian coordinate, a pair of integers.

typedef int coord;
typedef std::pair<coord,coord> point;
typedef std::list<point> config;

// The possible coordinates (0-based).

template <typename T>
void coords(coord size, const T &t) {
    for (coord i = 0; i < size; ++i) t(i);
}

// The possible queen positions.

template <typename T> class points_loop_inner {
    const T &t;
    coord i;
public:
    points_loop_inner(const T &_t, coord _i): t(_t), i(_i) {}
    void operator()(coord j) const { t(std::make_pair(i,j)); }
};

template <typename T> class points_loop_outer {
    coord size;
    const T &t;
public:
    points_loop_outer(coord _size, const T &_t): size(_size), t(_t) {}
    void operator()(coord i) const { coords(size, points_loop_inner<T>(t, i)); }
};

template <typename T>
void points(coord size, const T &t) {
    coords(size, points_loop_outer<T>(size, t));
}

// Given a board size, all the ways to add a queen to a configuration that do
// not conflict with the existing queens.

class addQueen_loop_pred {
    const point &p;
public:
    addQueen_loop_pred(const point &_p): p(_p) {}
    bool operator()(const point &q) const {
        return p.first == q.first
            || p.second == q.second
            || abs(p.first - q.first) == abs(p.second - q.second);
    }
};

template <typename T> class addQueen_loop {
    coord size;
    const config &c;
    const T &t;
public:
    addQueen_loop(coord _size, const config &_c, const T &_t):
        size(_size), c(_c), t(_t) {}
    void operator()(const point &p) const {
        if (std::find_if(c.begin(), c.end(), addQueen_loop_pred(p)) == c.end())
	    t(p);
    }
};

template <typename T>
void addQueen(coord size, const config &c, const T &t) {
    points(size, addQueen_loop<T>(size, c, t));
}

// Given a board size, all the ways to add a given number of queens to a
// configuration that do not conflict with the existing queens or among the new
// queens.

template <typename T> class addQueens_loop;

template <typename T>
void addQueens(coord size, const config &c, size_t n, const T &t) {
    if (n == 0)
        t(c);
    else
        addQueen(size, c, addQueens_loop<T>(size, c, n, t));
}

template <typename T> class addQueens_loop {
    coord size;
    const config &c;
    size_t n;
    const T &t;
public:
    addQueens_loop(coord _size, const config &_c, size_t _n, const T &_t):
        size(_size), c(_c), n(_n), t(_t) {}
    void operator()(const point &p) const {
        config cNew(c);
        cNew.push_front(p);
        addQueens(size, cNew, n-1, t);
    }
};

// Main program.

int main() {
    int n;
    std::cin >> n;
    addQueens(n, config(), n, print<config>());

    return 0;
}
