#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define nmax_def 220000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

class Graph_class {
public:
	bool graph_from1 = true;
	bool graph_tree = false;
	bool graph_weight = false;
	bool graph_digraph = false;
	int N, M;
	vector<pii> edgelist;
	vl edgeweight;
	vector<vi> adjlist;
	vector<vl> adjlistweight;
	vi adjnum;
	map<pii, int> uv_to_edge;

	vi adj_to_root;
	vector<ll> DP;
	vi vlist_from_root;
	vl xdist;

	vb x_visited;
	deque<int> x_que;

	// -------

	// -------

	void read_edge();
	void adjini();
	void visited_ini();
	void graph_BFS(ll BFS_ini);
	Graph_class Kruskal();
	void solve();

	bool xydist_def = false;
};

// ----- UnionFind -----

class UnionFind {
public:
	vi par;
	vi adjnum;
	int N;

	void UnionFind_ini(int Narg);
	int root(int x);
	void unite(int x, int y);
	bool same(int x, int y);
	int adjnum_func(int x);
};

void UnionFind::UnionFind_ini(int Narg) {
	N = Narg;
	adjnum.resize(N);
	par.resize(N);
	rep(i, N) {
		adjnum[i] = 1;
		par[i] = i;
	}
}

int UnionFind::root(int x) {
	if (par[x] == x)
		return x;
	par[x] = root(par[x]);
	return par[x];
}

void UnionFind::unite(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	if (rx == ry)
		return;
	par[rx] = ry;
	adjnum[ry] += adjnum[rx];
	return;
}

bool UnionFind::same(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

int UnionFind::adjnum_func(int x) {
	int rx = root(x);
	return adjnum[rx];
}

// ----- graph -----

void Graph_class::read_edge() {
	cin >> N;
	if (graph_tree)
		M = N - 1;// graph
	else
		cin >> M;
	edgelist.resize(M);
	edgeweight.resize(M, 1);
	rep(i, M) {
		if (graph_weight)
			cin >> edgelist[i].first >> edgelist[i].second >> edgeweight[i];
		else
			cin >> edgelist[i].first >> edgelist[i].second;
		if (graph_from1) {
			edgelist[i].first--;
			edgelist[i].second--;
		}
		if (edgelist[i].first > edgelist[i].second)
			swap(edgelist[i].first, edgelist[i].second);
		uv_to_edge[edgelist[i]] = i;
	}
	return;
}

void Graph_class::adjini() {
	adjnum.resize(N);
	xdist.resize(N, -1);
	adjlist.resize(N);
	if (graph_weight)
		adjlistweight.resize(N);
	adj_to_root.resize(N, -1);
	DP.resize(N, 0);
	rep(i, N)
		adjnum[i] = 0;
	rep(i, M) {
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		adjlist[x].push_back(y);
		if (!graph_digraph)
			adjlist[y].push_back(x);
		if (graph_weight) {
			ll xyweight = edgeweight[i];
			adjlistweight[x].push_back(xyweight);
			if (!graph_digraph)
				adjlistweight[y].push_back(xyweight);
		}
		adjnum[x]++;
		if (!graph_digraph)
			adjnum[y]++;
	}
	x_visited.resize(N);
	visited_ini();

	return;
}

void Graph_class::visited_ini() {
	rep(i, N) {
		x_visited[i] = false;
		adj_to_root[i] = -1;
	}
	x_que.clear();
}

void Graph_class::graph_BFS(ll BFS_ini) {
	visited_ini();
	x_que.push_back(BFS_ini);
	x_visited[BFS_ini] = true;

	// option
	xdist[BFS_ini] = 0;
	vlist_from_root.clear();
	vlist_from_root.push_back(BFS_ini);
	//cout << BFS_ini << endl;

	while (!x_que.empty()) {
		int x = x_que.front();
		x_que.pop_front();
		rep(i, adjnum[x]) {
			int x_new = adjlist[x][i];
			int dist_new = 1;
			if (graph_weight)
				dist_new = adjlistweight[x][i];
			if (!x_visited[x_new]) {
				x_visited[x_new] = true;
				x_que.push_back(x_new);

				// option
				adj_to_root[x_new] = x;
				vlist_from_root.push_back(x_new);
				xdist[x_new] = xdist[x] + dist_new;
				//cout << x_new << endl;
			}
		}
	}
	return;
}

Graph_class Graph_class::Kruskal() {
	assert(!graph_digraph);
	Graph_class tree;
	vector<pair<ll, pii> > edgeweight_sort(M);
	rep(i, M) {
		edgeweight_sort[i].first = edgeweight[i];
		edgeweight_sort[i].second = edgelist[i];
	}
	sort(edgeweight_sort.begin(), edgeweight_sort.end(), less<pair<ll, pii> >());
	UnionFind tree_uf;
	tree_uf.UnionFind_ini(N);
	tree.N = N;
	tree.M = 0;
	rep(i, M) {
		ll edgeweighttmp = edgeweight_sort[i].first;
		pii edgetmp = edgeweight_sort[i].second;
		if (!tree_uf.same(edgetmp.first, edgetmp.second)) {
			tree_uf.unite(edgetmp.first, edgetmp.second);
			tree.edgelist.push_back(edgetmp);
			tree.edgeweight.push_back(edgeweighttmp);
			tree.M++;
		}
	}
	tree.graph_from1 = true;
	tree.graph_tree = true;
	tree.graph_weight = true;
	tree.graph_digraph = false;

	tree.adjini();
	return tree;
}

void Graph_class::solve() {
	Graph_class tree = Kruskal();
	vb is_in_tree(M, false);
	rep(i, tree.M) {
		pii edgetmp = tree.edgelist[i];
		int n = uv_to_edge[edgetmp];
		is_in_tree[n] = true;
	}
	vb is_u_to_v(M, true);
	vb Vdim(N, false); // false : 偶数, true : 奇数
	rep(i, M) {
		if (is_in_tree[i])
			continue;
		pii edgetmp = edgelist[i];
		Vdim[edgetmp.first] = !Vdim[edgetmp.first];
	}

	tree.graph_BFS(0);
	rrep(i, tree.N) {
		int x = tree.vlist_from_root[i];
		if (i == 0) {
			if (!Vdim[x]) {
				rep(j, M) {
					if (!is_u_to_v[j])
						swap(edgelist[j].first, edgelist[j].second);
					cout << edgelist[j].first + 1 << " " << edgelist[j].second + 1 << endl;
				}
			}
			else
				cout << "-1" << endl;
			continue;
		}
		int x_root = tree.adj_to_root[x];
		pii edgetmp = make_pair(x_root, x);
		bool edgerev = false;
		if (x_root > x) {
			swap(edgetmp.first, edgetmp.second);
			edgerev = true;
		}
		is_u_to_v[uv_to_edge[edgetmp]] = (Vdim[x] == edgerev);
		Vdim[x_root] = (Vdim[x_root] == Vdim[x]);
		Vdim[x] = false;
	}
	return;
}

int main(void) {
	Graph_class graph;
	graph.read_edge();
	graph.adjini();
	graph.solve();
	return 0;
}

Measured memory_bytes: 35052