#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int maxN = 1e5 + 5, maxM = 2e5 + 5;
int N, M, timer, in[maxN];
bool even[maxN];
vector<pii> G[maxN];
pii ans[maxM];
// Depth-first search (DFS) function to traverse the graph
void dfs(int u, int p = -1)
{
// Mark the current node with a visitation timestamp
in[u] = ++timer;
// Iterate over all adjacent nodes
for (pii e : G[u]) {
int v = e.first, id = e.second;
// Skip the parent node to avoid traversing back
if (v != p) {
// If the adjacent node has not been visited
if (!in[v]) {
// Recursively perform DFS on the adjacent
// node
dfs(v, u);
// If the adjacent node has an even
// outdegree
if (even[v]) {
// Direct the edge from the current
// node to the adjacent node
ans[id] = { u, v };
// Toggle the outdegree of the current
// node
even[u] ^= true;
}
else {
// If the adjacent node has an odd
// outdegree Direct the edge from the
// adjacent node to the current node
ans[id] = { v, u };
// Toggle the outdegree of the adjacent
// node
even[v] ^= true;
}
}
else if (in[v] < in[u]) {
// If the adjacent node was visited earlier
// Toggle the outdegree of the current node
even[u] ^= true;
// Direct the edge from the current node to
// the adjacent node
ans[id] = { u, v };
}
}
}
}
int main()
{
// Predefined input
N = 4;
M = 4;
// List of edges
vector<pair<int, int> > edges
= { { 1, 3 }, { 3, 2 }, { 3, 4 }, { 1, 4 } };
// Construct the graph from the predefined edges
for (int i = 0; i < M; i++) {
cin >> edges[i].first >> edges[i].second;
int a = edges[i].first, b = edges[i].second;
// Add edge to adjacency list for node a
G[a].push_back({ b, i });
// Add edge to adjacency list for
// node b (undirected graph)
G[b].push_back({ a, i });
}
// Initialize all nodes to have even outdegrees
fill(even + 1, even + N + 1, true);
// Perform DFS traversal on all unvisited nodes
for (int i = 1; i <= N; i++) {
if (!in[i]) {
dfs(i);
}
}
// Check if all nodes have even outdegrees
bool good = true;
for (int i = 1; i <= N; i++) {
good &= even[i];
}
// Print the result
if (good) {
for (int i = 0; i < M; i++) {
// Print directed edges
printf("%d %d\n", ans[i].first, ans[i].second);
}
}
else {
// Print "IMPOSSIBLE" if any node has an odd
// outdegree
printf("IMPOSSIBLE\n");
}
return 0;
}