#include using namespace std; using ll = long long; int main() { constexpr int N = 6; int p[N][N] = {}; int a[2][N] = {}; int q = 35; for (int h = 0; h < 2; h++) { for (int i = 0; i < N; i++) { a[h][i] = (1 << N) - 1; } } while (q--) { int t = 0; for (int i = 0; i < N; i++) { int d; cin >> d; if (d < 0) exit(0); d--; t |= 1 << d; } t = ~t; int i1 = -1, j1 = -1, u = N * 2; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (p[i][j] == 0) { int s = __builtin_popcount(a[0][i] & t) + __builtin_popcount(a[1][j] & t); if (s < u) { u = s; i1 = i; j1 = j; } } } } cout << i1 + 1 << ' ' << j1 + 1 << endl; p[i1][j1] = 1; a[0][i1] &= ~t; a[1][j1] &= ~t; } return 0; }