In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him.

After a while the cashier has a lunch break and the people in the queue seat on the chairs in the waiting room in a random order.

When the lunch break was over, it turned out that nobody can remember the exact order of the people in the queue, but everyone remembers his number ai.

Your task is to restore the order in which the people stood in the queue if it is possible. There may be several acceptable orders, but you need to find any of them. Also, you need to print a possible set of numbers hi — the heights of people in the queue, so that the numbers ai are correct.

Input

The first input line contains integer n — the number of people in the queue (1 ≤ n ≤ 3000). Then n lines contain descriptions of the people as "namei ai" (one description on one line), where namei is a non-empty string consisting of lowercase Latin letters whose length does not exceed 10 characters (the i-th person's name), ai is an integer (0 ≤ ai ≤ n - 1), that represents the number of people who are higher and stand in the queue in front of person i. It is guaranteed that all names are different.

Output

If there's no acceptable order of the people in the queue, print the single line containing "-1" without the quotes. Otherwise, print in n lines the people as "namei hi", where hi is the integer from 1 to 109 (inclusive), the possible height of a man whose name is namei. Print the people in the order in which they stand in the queue, starting from the head of the queue and moving to its tail. Numbers hi are not necessarily unique.

Examples

Input

4
a 0
b 2
c 0
d 0


Output

a 150
c 170
d 180
b 160


Input

4
vasya 0
petya 1
manya 3
dunay 3


Output

-1

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Sorting

Constructive algorithms


Solutions:
def solve(arr, n):
	arr.sort()
	names = [x[1] for x in arr]
	counts = [x[0] for x in arr]
	segments = []
	curr_count = counts[0]
	curr_len = 0
	L = 0
	for i in range(n):
		if counts[i] == curr_count:
			curr_len += 1
		else:
			segments.append((L, i - 1))
			L = i
			curr_count = counts[i]
			curr_len = 1
	segments.append((L, n - 1))
	h = [1 for i in range(n)]
	tall_dudes = 0
	for j in range(len(segments)):
		segment = segments[j]
		(L, R) = segment
		for i in range(L - 1, -1, -1):
			if tall_dudes < counts[L] and h[i] == 1:
				h[i] = 10 ** 9 - j
				tall_dudes += 1
		if tall_dudes < counts[L]:
			print(-1)
			return
	for i in range(n):
		print(names[i], h[i])
n = int(input())
a = []
for i in range(n):
	x = input().split()
	a.append((int(x[1]), x[0]))
solve(a, n)


n = int(input())
a = []
for _ in range(n):
	x = input().split()
	a.append((x[0], int(x[1])))
a.sort(key=lambda x: x[1])
ans = []
for x in a:
	if x[1] > len(ans):
		print(-1)
		exit()
	ans.insert(x[1], (x[0], n))
	n -= 1
for x in ans:
	print(x[0], x[1])


n = int(input())
arr = []
for i in range(n):
	(a, b) = input().split()
	arr.append([a, int(b)])
arr.sort(key=lambda x: x[1])
ans = []
for x in arr:
	if x[1] > len(ans):
		print(-1)
		exit()
	ans.insert(x[1], (x[0], n))
	n -= 1
for x in ans:
	print(x[0], x[1])


(ans, pr) = (list(), list())
for _ in range(int(input())):
	(a, b) = input().split()
	ans.append([int(b), a])
ans.sort()
v = len(ans)
for x in ans:
	if x[0] > len(pr):
		print(-1)
		break
	pr.insert(x[0], (x[1], v))
	v -= 1
else:
	for _ in pr:
		print(_[0], _[1])


from collections import defaultdict
n = int(input())
p = defaultdict(list)
for i in range(n):
	(a, k) = input().split()
	p[int(k)].append(a)
t = list(p.keys())
t.sort()
(j, n) = (0, len(t))
(u, v) = ([0] * n, [[] for k in range(n)])
(c, y) = ([0] * n, 0)
for i in t:
	(d, x) = (i - j, y - 1)
	while d:
		if x == -1:
			print(-1)
			exit(0)
		if d < u[x]:
			u[x] -= d
			v[x].append((y, d))
			break
		else:
			d -= u[x]
			v[x].append((y, u[x]))
			u[x] = 0
			x = c[x]
	c[y] = x
	j = i
	u[y] = len(p[i])
	y += 1
(y, s, n) = (0, [], 2 * n)
for i in t:
	j = u[y]
	v[y].reverse()
	for a in p[i][:j]:
		s.append(a + ' ' + str(y + 1))
	for (x, k) in v[y]:
		for a in p[i][j:j + k]:
			s.append(a + ' ' + str(n - x))
		j += k
	y += 1
print('\n'.join(s))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
status = []
have = {}
for i in range(n):
	(name, s) = input().split()
	have[name] = int(s)
	status.append((int(s), name))
status.sort()
ans = [i[1] for i in status]
rem = 0
height = [0, 10 ** 9]
queue = []
ok = True
for i in range(n):
	if have[ans[i]] > len(queue):
		ok = False
		break
	k = have[ans[i]]
	key = n - len(queue)
	queue.insert(k, (ans[i], key))
if not ok:
	print(-1)
	exit()
for i in queue:
	print(*i)


n = int(input())
arr = [input().split() for _ in range(n)]
arr = [[int(arr[i][1]), arr[i][0]] for i in range(n)]
arr.sort()
res = []
for i in range(n):
	res.append(i - arr[i][0])
	if res[i] < 0:
		print(-1)
		exit()
	for j in range(i):
		if res[j] >= res[i]:
			res[j] += 1
for i in range(n):
	print(arr[i][1], res[i] + 1)


n = int(input())
ppl = []
for i in range(n):
	inp = input().split()
	ppl.append((int(inp[1]), inp[0]))
ppl.sort()
res = []
for i in range(n):
	res.append(i - ppl[i][0])
	if res[i] < 0:
		print(-1)
		exit()
	for j in range(i):
		if res[j] >= res[i]:
			res[j] += 1
for i in range(n):
	print(ppl[i][1], res[i] + 1)


n = int(input())
a = []
for _ in range(n):
	(name, num) = input().split()
	a.append([name, int(num)])
a = sorted(a, key=lambda x: x[1])
h = []

def solve(a):
	h = []
	for (name, num) in a:
		if num > len(h):
			return (False, -1)
		if num == 0:
			if len(h) == 0:
				h.append([name, 1])
			else:
				h.append([name, h[-1][1] + 1])
		else:
			h = h[:-num] + [[name, h[-num][1]]] + h[-num:]
			for h_ in h[-num:]:
				h_[1] += 1
	h = {name: h_ for (name, h_) in h}
	for x in a:
		x[1] = h[x[0]]
	return (True, a)
(flg, ans) = solve(a)
if flg == False:
	print(ans)
else:
	for (name, h) in ans:
		print(name + ' ' + str(h))


n = int(input())
a = sorted([list(map(lambda x: x if x[0] >= 'a' and x[0] <= 'z' else int(x), input().split()))[::-1] for i in range(n)])
fl = 1
ans = []
for i in range(len(a)):
	(v, name) = a[i]
	if i == 0:
		if v > 0:
			fl = 0
			break
		else:
			ans.append((name, n))
	else:
		if v > i:
			fl = 0
			break
		ans.insert(v, (name, n - i))
if not fl:
	print(-1)
else:
	for i in ans:
		print(*i)


n = int(input())

def func(s):
	(name, a) = s.split()
	return [int(a), name]
arr = [func(input()) for i in range(n)]
arr.sort()
flag = True
for i in range(n):
	if i < arr[i][0]:
		flag = False
		break
if flag:
	h = [0] * n
	for i in range(n // 2):
		hi = h[i] = 20000 * (i + 1 - arr[i][0])
		for x in range(i):
			if h[x] >= hi:
				h[x] += 20000
	for i in range(n // 2, n):
		hi = h[i] = i + 1 - arr[i][0]
		for x in range(n // 2, i):
			if h[x] >= hi:
				h[x] += 1
	hh = sorted([[h[i], i] for i in range(n // 2, n)])
	hh = sorted([[hh[i][1], i + 1] for i in range(n - n // 2)])
	for i in range(n // 2, n):
		h[i] += 20000 * (h[i] - hh[i - n // 2][1])
	for i in range(n):
		print(arr[i][1], h[i])
else:
	print(-1)


n = int(input())
a = []
for i in range(n):
	(s, c) = input().split()
	a.append((s, int(c)))
a.sort(key=lambda x: x[1])
ans = []
for i in range(n):
	if len(ans) < a[i][1]:
		print(-1)
		exit(0)
	ans.insert(a[i][1], (a[i][0], n - i))
for (s, a) in ans:
	print(s, a)


def question3():
	people = int(input())
	front_more_height = []
	for i in range(people):
		(name, front) = input().split()
		front = int(front)
		front_more_height.append([name, front])
	front_more_height.sort(key=lambda x: x[1])
	max1 = people ** 2
	n = people
	ans = []
	for i in range(people):
		if front_more_height[i][1] <= i:
			ans.insert(front_more_height[i][1], [front_more_height[i][0], n])
		else:
			return [-1, []]
		n -= 1
	return [1, ans]
remained_test_cases = 1
while remained_test_cases > 0:
	ans = question3()
	if ans[0] == -1:
		print(-1)
	else:
		for i in range(len(ans[1])):
			print(ans[1][i][0], ans[1][i][1])
	remained_test_cases -= 1


n = int(input())
arr = []
for i in range(n):
	(a, b) = list(map(str, input().split()))
	b = int(b)
	arr.append([b, a])
arr.sort()
ans = []
for i in arr:
	if i[0] > len(ans):
		print(-1)
		exit()
	ans.insert(i[0], (i[1], n))
	n -= 1
for i in ans:
	print(i[0], i[1])


import sys
n = int(input())
person = []
for i in range(n):
	person.append(input().split())
person.sort(key=lambda x: int(x[1]))
high = 10 ** 9
low = 1
cntHigh = 0
for i in range(n):
	dif = int(person[i][1]) - cntHigh
	for j in range(i - 1, -1, -1):
		if dif == 0:
			break
		if person[j][2] < high:
			person[j][2] = high
			high -= 1
			cntHigh += 1
			dif -= 1
	if dif > 0:
		print('-1')
		sys.exit(0)
	person[i] = [person[i][0], person[i][1], low]
	low += 1
for p in person:
	print(p[0], p[2])


from sys import stdin
from collections import defaultdict
n = int(stdin.readline().strip())
name_dict = dict()
name_list = []
for _ in range(n):
	(name, num) = list(stdin.readline().split())
	num = int(num)
	name_dict[name] = num
	name_list.append([name, num])
name_list.sort(key=lambda x: x[1])
ans = dict()
ans[name_list[0][0]] = 3001
cur = [3001]
for i in range(1, n):
	(name, rank) = name_list[i]
	if len(cur) < rank:
		print(-1)
		exit()
	if rank == len(cur):
		mn = min(cur) - 1
		r = mn
	else:
		r = cur[rank]
		mn = float('inf')
		for j in ans:
			if ans[j] <= r:
				ans[j] -= 1
			mn = min(ans[j], mn)
	ans[name] = r
	cur.append(mn)
for i in ans:
	print(i, ans[i])