Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] += 1

if m%2 == 1:
	print(-1)
	sys.exit()

def dfs(start):
	prev = [(-1, -1) for _ in range(n)]
	prev[start] = (start, -1)
	q = [start]
	while q:
		l = q.pop()
		if l != start and eff[l]%2 == 1:
			eff[start] += 1
			eff[l] += 1
			break
		for v, i in adj[l]:
			if prev[v][0] < 0:
				prev[v] = (l, i)
				q.append(v)
	s, t = l, prev[l][1]
	while t >= 0:
		is_reversed[t] ^= 1
		s = prev[s][0]
		t = prev[s][1]

odd = [i for i in range(n) if eff[i]%2 == 1]
for o in odd:
	if eff[o]%2 == 1:
		dfs(o)

for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
visited = [False for _ in range(n)]
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] ^= 1

if m%2 == 1:
	print(-1)
	sys.exit()

def dfs(x, e):
	for v, i in adj[x]:
		if not visited[v]:
			visited[v] = True
			dfs(v, i)
	if e == -1:
		return
	else:
		if eff[x] == 1:
			is_reversed[e] ^= 1
			eff[x] ^= 1
			eff[(edges[e][0]-1) * (edges[e][1]-1) // x] ^= 1
		return

visited[0] = True
dfs(0, -1)
for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] += 1

if m%2 == 1:
	print(-1)
	sys.exit()

def bfs(start):
	prev = [(-1, -1) for _ in range(n)]
	prev[start] = (start, -1)
	q = deque([start])
	while q:
		l = q.pop()
		if l != start and eff[l]%2 == 1:
			eff[start] += 1
			eff[l] += 1
			break
		for v, i in adj[l]:
			if prev[v][0] < 0:
				prev[v] = (l, i)
				q.appendleft(v)
	s, t = l, prev[l][1]
	while t >= 0:
		is_reversed[t] ^= 1
		s = prev[s][0]
		t = prev[s][1]

odd = [i for i in range(n) if eff[i]%2 == 1]
for o in odd:
	if eff[o]%2 == 1:
		bfs(o)

for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
visited = [False for _ in range(n)]
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] ^= 1

if m%2 == 1:
	print(-1)
	sys.exit()

def dfs(x, e):
	for v, i in adj[x]:
		if not visited[v]:
			visited[v] = True
			dfs(v, i)
	if e == -1:
		return
	else:
		if eff[x] == 1:
			is_reversed[e] ^= 1
			eff[x] ^= 1
			eff[(edges[e][0]-1) * (edges[e][1]-1) // x] ^= 1
		return

visited[0] = True
dfs(0, -1)
for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] += 1

if m%2 == 1:
	print(-1)
	sys.exit()

def bfs(start):
	prev = [(-1, -1) for _ in range(n)]
	prev[start] = (start, -1)
	q = deque([start])
	while q:
		l = q.pop()
		if l != start and eff[l]%2 == 1:
			eff[start] += 1
			eff[l] += 1
			break
		for v, i in adj[l]:
			if prev[v][0] < 0:
				prev[v] = (l, i)
				q.appendleft(v)
	s, t = l, prev[l][1]
	while t >= 0:
		is_reversed[t] ^= 1
		s = prev[s][0]
		t = prev[s][1]

odd = [i for i in range(n) if eff[i]%2 == 1]
for o in odd:
	if eff[o]%2 == 1:
		bfs(o)

for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])

Fixed submission:
import sys
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
eff = [0 for _ in range(n)]
edges = []
visited = [False for _ in range(n)]
is_reversed = [0 for _ in range(m)]

for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append([b-1, i])
	adj[b-1].append([a-1, i])
	edges.append([a, b])
	eff[a-1] ^= 1

if m%2 == 1:
	print(-1)
	sys.exit()

def dfs(x, e):
	for v, i in adj[x]:
		if not visited[v]:
			visited[v] = True
			dfs(v, i)
	if e == -1:
		return
	else:
		if eff[x] == 1:
			is_reversed[e] ^= 1
			eff[x] ^= 1
			eff[(edges[e][0]-1) * (edges[e][1]-1) // x] ^= 1
		return

visited[0] = True
dfs(0, -1)
for i in range(m):
	if is_reversed[i]:
		print(*edges[i][::-1])
	else:
		print(*edges[i])