A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.

Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code of the $i$-th card is $p_i$.

Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $n$ codes would become different.

Formally, in one step, Polycarp picks $i$-th card ($1 \le i \le n$), then in its PIN code $p_i$ selects one position (from $1$ to $4$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.

Polycarp quickly solved this problem. Can you solve it?


-----Input-----

The first line contains integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then test cases follow.

The first line of each of $t$ test sets contains a single integer $n$ ($2 \le n \le 10$) — the number of Polycarp's bank cards. The next $n$ lines contain the PIN codes $p_1, p_2, \dots, p_n$ — one per line. The length of each of them is $4$. All PIN codes consist of digits only.


-----Output-----

Print the answers to $t$ test sets. The answer to each set should consist of a $n + 1$ lines

In the first line print $k$ — the least number of changes to make all PIN codes different. In the next $n$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.


-----Example-----
Input
3
2
1234
0600
2
1337
1337
4
3139
3139
3139
3139

Output
0
1234
0600
1
1337
1237
3
3139
3138
3939
6139

Difficulty: MEDIUM
Tags: Implementation

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
try:
	n = int(input())
	for i in range(n):
		count = 0
		sub = 0
		u = int(input())
		b = []
		for j in range(u):
			o = str(input())
			b.append(o)
		d = set(b)
		for r in d:
			sub = sub + (b.count(r) - 1)
		count = count + sub
		print(count)
		for (er, gh) in enumerate(b):
			if b.count(gh) == 1:
				continue
			else:
				for x in '0123456789':
					new = x + gh[1:]
					if new in b:
						continue
					else:
						b[er] = new
						break
		print(*b, sep='\n')
except Exception as e:
	pass


def main():

	def solve():
		n = int(input())
		pp = []
		for _ in range(n):
			pp.append(list(input()))
		avail = [str(a) for a in range(0, 10)]
		for p in pp:
			if p[0] in avail:
				avail.remove(p[0])
		count = 0
		for i in range(1, n):
			if pp[i] in pp[:i]:
				pp[i][0] = avail.pop(0)
				count += 1
		print(count)
		for p in pp:
			print(''.join(p))
	q = int(input())
	for _ in range(q):
		solve()
main()


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	n = int(z())
	l = [z().strip() for _ in range(n)]
	ch = 0
	for (i, b) in enumerate(l):
		if l.count(b) > 1:
			for x in '0123456789':
				l[i] = x + b[1:]
				if l.count(l[i]) == 1:
					break
			ch += 1
	print(ch)
	for i in l:
		print(i)


from math import ceil
from collections import defaultdict
for q in range(int(input())):
	s = []
	n = int(input())
	for i in range(n):
		s.append(list(input()))
	seen = [0] * 10
	M = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if s[i] == s[j]:
				for k in range(n):
					seen[int(s[k][0])] = 1
				for k in range(10):
					if seen[k] == 0:
						s[i][0] = str(k)
						seen[k] = 1
						M += 1
						break
	print(M)
	for i in range(n):
		print(''.join(s[i]))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	st = [[str(i) for i in range(10)] for _ in range(4)]
	d = defaultdict(int)
	l = []
	for _ in range(n):
		s = input()
		l.append(s)
		for i in range(4):
			st[i][int(s[i])] = '-1'
	r = []
	c = 0
	for xi in range(n):
		s = l[xi]
		p = [i for i in s]
		if d[s] == 1:
			c += 1
			f = 0
			for i in range(4):
				for j in range(10):
					if st[i][j] != '-1':
						p[i] = st[i][j]
						st[i][j] = '-1'
						f = 1
						break
				if f == 1:
					break
			x = ''.join(p)
			d[x] = 1
			r.append(x)
		else:
			d[s] = 1
			r.append(s)
	print(c)
	print(*r, sep='\n')


def ListToString(lista):
	a = ''
	for i in lista:
		a += str(i)
	return a

def VerificaRepetido(pinRepetido):
	a = list(pinRepetido)
	for j in range(4):
		for k in range(1, 10):
			c = divmod(int(a[j]), 9)
			if int(c[1]) > 5:
				a[j] = int(c[1]) + 1
			else:
				a[j] = 0
				a[j] = int(c[1]) + 1
			s = ListToString(a)
			if s not in saida:
				saida[repetidos[i - 1]] = s
				return
			else:
				continue
t = int(input())
for x in range(0, t):
	n = int(input())
	entrada = []
	for i in range(n):
		entrada.append(input())
	repetidos = []
	saida = [0] * len(entrada)
	for i in range(len(entrada)):
		if entrada[i] in saida:
			repetidos.append(i)
			repetidos.append(entrada[i])
		else:
			saida[i] = entrada[i]
	for i in range(1, len(repetidos), 2):
		VerificaRepetido(repetidos[i])
	print(len(repetidos) // 2)
	for i in saida:
		print(i)


from random import randrange
T = int(input())
for I in range(T):
	N = int(input())
	L = list(range(N))
	for J in range(N):
		L[J] = input()
	print(N - len(set(L)))
	print(L[0])
	for J in range(1, N):
		X = 0
		if L.count(L[J]) != 1:
			for X in range(0, 4):
				F = 0
				N = 0
				while True:
					Y = L[J][0:X] + str(randrange(0, 9)) + L[J][X + 1:]
					N += 1
					if Y not in L:
						L[J] = Y
						F = 1
						break
					if N == 9:
						break
				if F == 1:
					break
		print(L[J])


import random

def removeDup():
	l = []
	n = int(input())
	for _ in range(n):
		l.append(input())
	changes = 0
	for e in l:
		while l.count(e) > 1:
			index = l.index(e)
			changes += 1
			while True:
				e1 = l[index]
				new_val = random.randint(0, 8)
				r_index = random.randint(0, 3)
				if r_index == 3:
					e1 = e[:3] + str(new_val)
				else:
					e1 = e[:r_index] + str(new_val) + e[r_index + 1:]
				if l.count(e1) == 0:
					break
			l[index] = e1
	print(changes)
	print(*l, sep='\n')
for _ in range(int(input())):
	removeDup()


import sys
from collections import defaultdict

def input():
	return sys.stdin.readline().strip()
for i in range(int(input())):
	n = int(input())
	dic = defaultdict(int)
	got = set()
	ind = defaultdict(list)
	ans = [0 for _ in range(n)]
	cnt = 0
	for j in range(n):
		s = input()
		ind[s].append(j)
		dic[s] += 1
		got.add(s)
	for (k, v) in dic.items():
		ans[ind[k].pop()] = k
		for j in range(v - 1):
			cnt += 1
			for pos in range(4):
				found = False
				for add in range(1, 10):
					trynew = [int(x) for x in list(k)]
					trynew[pos] = (trynew[pos] + add) % 10
					newstr = ''.join((str(x) for x in trynew))
					if newstr not in got:
						found = True
						ans[ind[k].pop()] = newstr
						got.add(newstr)
						break
				if found:
					break
	print(cnt)
	print('\n'.join(ans))


def to_str(num):
	a = num // 1000 % 10
	b = num // 100 % 10
	c = num // 10 % 10
	d = num % 10
	return str(a) + str(b) + str(c) + str(d)
t = int(input())
for tt in range(t):
	n = int(input())
	a = []
	for _ in range(n):
		a.append(int(input()))
	tmp = list(a)
	for i in range(n):
		m = a[i]
		while a.count(a[i]) != 1 and a[i] != 9999:
			a[i] += 1
		cur1 = 0
		mm = a[i]
		x = to_str(m)
		y = to_str(a[i])
		for j in range(4):
			if x[j] != y[j]:
				cur1 += 1
		a[i] = m
		while a.count(a[i]) != 1 and a[i] != 0:
			a[i] -= 1
		x = to_str(m)
		y = to_str(a[i])
		cur2 = 0
		for j in range(4):
			if x[j] != y[j]:
				cur2 += 1
		if cur1 < cur2 or a[i] == 0:
			a[i] = mm
	ans = 0
	for i in range(n):
		x = to_str(a[i])
		y = to_str(tmp[i])
		for j in range(4):
			if x[j] != y[j]:
				ans += 1
	print(ans)
	for w in a:
		print(to_str(w))


import os
import sys
from io import BytesIO, IOBase
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')

def check(p, s):
	for i in range(len(p)):
		cnt = 0
		for j in range(4):
			if s[j] == p[i][j]:
				cnt += 1
		if cnt == 4:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	p = [input() for i in range(n)]
	ft = 0
	for i in range(n):
		if p[i] not in p[:i]:
			continue
		f = 0
		for j in range(4):
			for k in range(10):
				var = list(p[i])
				var[j] = str(k)
				t = check(p, var)
				if t == True:
					f = 1
					ft += 1
					p[i] = ''.join(var)
					break
			if f == 1:
				break
	print(ft)
	for g in range(n):
		print(p[g])


def are_there_equals(card, cards, avoid):
	ans = False
	for i in range(len(cards)):
		if i != avoid:
			if card == cards[i]:
				ans = True
				break
	return ans
t = int(input())
for teste in range(t):
	n = int(input())
	cards = []
	changes = 0
	for i in range(n):
		cards.append(input())
	for i in range(n):
		card = cards[i]
		digit = 0
		changed = False
		while are_there_equals(card, cards, i):
			changed = True
			modified_string = list(card)
			modified_string[0] = str(digit)
			card = ''.join(modified_string)
			digit += 1
		if changed:
			changes += 1
		cards[i] = card
	print(changes)
	for card in cards:
		print(card)


for _ in range(int(input())):
	n = int(input())
	L = []
	for i in range(n):
		L.append(input())
	x = set(L)
	print(n - len(x))
	new = []
	for i in L:
		if i not in new:
			new.append(i)
		else:
			for j in range(10):
				y = str(j) + i[1:]
				if y not in x:
					new.append(y)
					x.add(y)
					break
	for i in range(n):
		print(''.join(new[i]))


def compute(n, arr):
	changed = 0
	for i in range(n):
		for j in range(0, i):
			if arr[i] == arr[j]:
				changed += 1
				cur = 0
				res = True
				while res:
					temp = str(cur) + arr[i][1:]
					temp_cur = 0
					for k in range(n):
						if k == i:
							pass
						elif arr[k] == temp:
							temp_cur += 1
							cur += 1
							break
					if not temp_cur:
						res = False
				arr[i] = temp
				break
	print(changed)
	for i in arr:
		print(i)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(input())
	compute(n, arr)


for _ in range(int(input())):
	n = int(input())
	occup = [0] * 10000
	ides = [[] for _ in range(10000)]
	pins = [0] * n
	for k in range(n):
		X = list(map(int, list(input())))
		X.reverse()
		for i in range(4):
			pins[k] += X[i] * 10 ** i
		ides[pins[k]].append(k)
		occup[pins[k]] += 1
	change = 0
	for i in range(10000):
		while occup[i] > 1:
			cut = i - i % 10
			for j in range(10):
				if occup[cut + j] == 0:
					change += 1
					occup[cut + j] = 1
					pins[ides[i][-1]] = cut + j
					ides[i].pop()
					break
			occup[i] -= 1
	print(change)
	for pin in pins:
		pin = str(pin)
		print('0' * (4 - len(pin)) + pin)


for i in range(int(input())):
	n = int(input())
	p = []
	ch = [0 for j in range(n)]
	us = [0 for j in range(10)]
	for j in range(n):
		p.append(int(input()))
		us[int(p[j] / 1000)] = 1
	for j in range(n):
		for k in range(j + 1, n):
			if p[j] == p[k]:
				for x in range(n):
					if us[x] == 0:
						p[k] = p[k] % 1000 + 1000 * x
						us[x] = 1
						ch[k] += 1
						break
	print(sum(ch))
	print('\n'.join(('0' * (4 - len(str(j))) + str(j) for j in p)))


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

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')

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()]
for _ in range(Int()):
	n = Int()
	a = []
	for i in range(n):
		a.append(Int())
	ans = 0
	for i in range(n - 1):
		if a[i] in a[i + 1:]:
			ans += 1
			while a[i] in a[:i] + a[i + 1:]:
				a[i] = (a[i] + 1000) % 10000
	print(ans)
	for i in a:
		print('0' * (4 - len(str(i))), i, sep='')


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	p = []
	for i in range(n):
		p.append(list(input()))
	ans = 0
	cnt = 0
	for i in range(n):
		v = dict()
		for j in range(i + 1, n):
			if p[i] == p[j]:
				cnt += 1
				for c in range(10):
					if str(c) == p[i][0]:
						continue
					p[j][0] = str(c)
					if p.count(p[j]) <= 1:
						break
	print(cnt)
	for i in range(n):
		print(''.join(p[i]))


from difflib import SequenceMatcher
t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		a.append(int(input().strip()))
	b = a.copy()
	a.sort()
	op = 0
	j = 0
	oparr = []
	while j < n:
		c = 0
		oparr.append(a[j])
		x = a[j] % 1000
		y = a[j] // 1000
		while j < n - 1 and a[j + 1] == a[j]:
			c = c + 1
			j += 1
		op = op + c
		xx = 0
		while c:
			yy = xx * 1000 + x
			if yy in oparr or yy in a:
				xx += 1
			else:
				oparr.append(yy)
				xx += 1
				c -= 1
		j += 1
	print(op)
	for j in range(n):
		if b[j] in oparr:
			oparr.pop(oparr.index(b[j]))
			print(format(b[j], '04'))
		else:
			str1 = str(format(b[j], '04'))
			for k in range(len(oparr)):
				if oparr[k] in b:
					continue
				str2 = str(format(oparr[k], '04'))
				seqMatch = SequenceMatcher(None, str1, str2)
				match = seqMatch.find_longest_match(0, len(str1), 0, len(str2))
				if match.size == 3:
					print(format(oparr[k], '04'))
					oparr.pop(k)
					break


for t in range(int(input())):
	n = int(input())
	a = [input() for x in range(n)]
	ans = 0
	for i in range(n):
		if a.count(a[i]) > 1:
			for j in range(10):
				if a[i][:3] + str(j) not in a:
					a[i] = a[i][:3] + str(j)
					break
			ans += 1
	print(ans)
	for x in a:
		print(x)


for i in range(int(input())):
	n = int(input())
	p = []
	ans = 0
	for i in range(n):
		p.append(input())
	for i in range(n):
		if p[i] in p[i + 1:]:
			ans += 1
			j = 0
			while p[i] in p[i + 1:] + p[:i]:
				p[i] = p[i][:3] + str(j)
				j += 1
	print(ans)
	for i in range(n):
		print(p[i])


t = int(input())
for test in range(t):
	n = int(input())
	q = []
	for i in range(n):
		p = int(input())
		q.append(p)
	r = []
	steps = 0
	for i in range(n):
		p = q[i]
		if p not in r:
			r.append(p)
		else:
			steps += 1
			flag = True
			a = p // 10 % 10
			while flag:
				for d in list(range(-(p % 10), 10 - p % 10)) + list(range(-a * 10, 100 - a * 10, 10)):
					pp = p + d
					if pp not in q and pp not in r:
						r.append(pp)
						flag = False
						break
	print(steps)
	for j in range(len(r)):
		if r[j] < 1000:
			print(0, end='')
			if r[j] < 100:
				print(0, end='')
				if r[j] < 10:
					print(0, end='')
		print(r[j])


tc = int(input())
for i in range(tc):
	n = int(input())
	s = ['' for i in range(n)]
	used = [0 for i in range(10)]
	for i in range(n):
		s[i] = input()
		used[ord(s[i][3]) - ord('0')] = 1
	ret = 0
	for i in range(n):
		for j in range(n):
			repeat = 0
			if i != j and s[i] == s[j]:
				repeat = 1
			if repeat == 1:
				ret += 1
				for k in range(10):
					if not used[k]:
						used[k] = 1
						s[i] = s[i][0:3] + chr(k + ord('0'))
						break
	print(ret)
	for i in range(n):
		print(s[i])


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	pins = []
	for __ in range(n):
		pins.append(input().strip())
	lset = set(pins)
	dick = {}
	ans = 0
	for i in lset:
		dick[i] = pins.count(i)
		ans += dick[i] - 1
	answer = []
	mine = {}
	kins = pins.copy()
	for i in pins:
		if i not in mine:
			answer.append(i)
			mine[i] = 1
			while i in kins:
				kins.remove(i)
		else:
			new = list(i)
			for j in range(10):
				new[0] = str(j)
				x = ''.join(new)
				if x in kins or x in answer:
					continue
				else:
					mine[x] = mine.get(x, 0) + 1
					answer.append(x)
					break
	print(ans)
	for i in answer:
		print(i)


t = int(input())
for nt in range(t):
	n = int(input())
	a = [None] * n
	tc = []
	d = set()
	for i in range(n):
		a[i] = input()
		if a[i] in d:
			tc += [i]
		d.add(a[i])
	for i in tc:
		for j in range(10):
			if a[i][:3] + str(j) not in d:
				a[i] = a[i][:3] + str(j)
				d.add(a[i])
				break
	print(len(tc))
	for i in a:
		print(i)


cases = int(input())
for case in range(cases):
	card_dict = {}
	cards_number = int(input())
	pin_list = []
	for card in range(cards_number):
		key = input()
		pin_list.append(key)
		if card_dict.get(key):
			card_dict[key] += 1
		else:
			card_dict[key] = 1
	changes = 0
	for (key, value) in card_dict.items():
		while value > 1:
			for i in range(10):
				if key[:3] + str(i) not in pin_list:
					for j in range(len(pin_list) - 1, -1, -1):
						if pin_list[j] == key:
							pin_list[j] = key[:3] + str(i)
							break
					changes += 1
					break
			value -= 1
	print(changes)
	for pin in pin_list:
		print(pin)


vis = {}

def get_another(x):
	for j in range(4):
		for k in range(9):
			res = x[:j] + chr(ord('0') + k) + x[j + 1:]
			if vis.get(res, 0) == 0:
				vis[res] = 1
				return res
	return ''
t = int(input())
all_res = ''
for _ in range(t):
	vis = {}
	n = int(input())
	arr = list((input() for _ in range(n)))
	for i in arr:
		vis[i] = vis.get(i, 0) + 1
	res = 0
	for i in range(n):
		if vis[arr[i]] > 1:
			y = get_another(arr[i])
			vis[arr[i]] -= 1
			arr[i] = y
			res += 1
	all_res += str(res) + '\n'
	all_res += '\n'.join(arr) + '\n'
print(all_res)


def mm(i):
	l2 = ''.join((k[i] for k in a))
	for p in range(10):
		x = str(p)
		if x not in l2:
			return x
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	ans = 0
	for i in range(4):
		d = {}
		for j in range(len(a)):
			lol = a[j]
			if lol[i] not in d:
				d[lol[i]] = j
			elif a[d[lol[i]]] == lol:
				ans += 1
				a[j][i] = mm(i)
			else:
				continue
	print(ans)
	for x in a:
		for y in x:
			print(y, end='')
		print()


for _ in range(int(input())):
	n = int(input())
	d = dict()
	s = []
	m = []
	for i in range(n):
		x = input()
		m.append([x, i])
		if not d.get(x):
			d[x] = 1
		else:
			d[x] += 1
	m.sort()
	ans = 0
	w = 0
	vect = [0] * n
	while w < len(m):
		v = d[m[w][0]]
		k = m[w][0]
		w += v
		if v == 1:
			s.append(k)
			continue
		s.append(k)
		v -= 1
		while v > 0:
			f = 0
			for i in range(9):
				for j in range(4):
					st = ''
					st = k[:j] + str(i) + k[j + 1:]
					if not d.get(st):
						ans += 1
						d[st] = 1
						s.append(st)
						f = 1
						break
				if f == 1:
					break
			v -= 1
	print(ans)
	vt = []
	for i in range(n):
		vt.append([s[i], m[i][1]])
	vt.sort(key=lambda x: x[1])
	for i in range(n):
		print(vt[i][0])


digits = '0123456789'

def main():
	n = int(input())
	p = [input() for _ in range(n)]
	s = set()
	step = 0
	for i in range(n):
		num = p[i]
		if num not in s:
			s.add(num)
			continue
		else:
			state = False
			for j in range(4):
				for digit in digits:
					temp = list(num)
					temp[j] = digit
					temp = ''.join(temp)
					if temp not in s and temp not in p:
						step += 1
						s.add(temp)
						p[i] = temp
						state = True
						break
				if state:
					break
	print(step, *p, sep='\n')
t = int(input())
for _ in range(t):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	a = dict()
	b = []
	for i in range(n):
		c = input()
		a[c] = a.get(c, -1) + 1
		b.append(c)
	print(sum(a.values()))
	rlb = list(range(len(b)))
	for i in rlb:
		v = b[i]
		if a.get(v, 0) == 0:
			print(v)
		else:
			(v, vo) = (v[1:], v)
			for i in range(10):
				if not str(i) + v in a:
					a[str(i) + v] = 0
					a[vo] -= 1
					print(str(i) + v)
					break


from sys import *
from math import *
for _ in range(int(input())):
	n = int(input())
	lis = []
	for i in range(n):
		p = input()
		lis.append(int(p))
	ans = 0
	for i in range(n - 1):
		if lis[i] in lis[i + 1:]:
			ans += 1
			while lis[i] in lis[:i] + lis[i + 1:]:
				lis[i] += 1000
				lis[i] %= 10000
	print(ans)
	for i in lis:
		print('%04d' % int(i))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, lis):
	c = 0
	for i in lis:
		tmp = 0
		for j in range(10):
			if lis.count(i) == 1:
				break
			else:
				tmp = 1
				i[-1] = str(j)
		c += tmp
	print(c)
	for i in lis:
		print(''.join(i))
for _ in range(int(input())):
	lis = []
	n = int(input())
	for i in range(n):
		lis.append(list(str(input())[:-1]))
	solve(n, lis)


t = int(input())
for i in range(t):
	n = int(input())
	w = []
	asd = set()
	q = set()
	for j in range(n):
		c = input()
		q |= {c[-1]}
		if c in w:
			asd |= {j}
		w.append(c)
	print(len(asd))
	y = 0
	for j in range(n):
		if j not in asd:
			print(w[j])
		else:
			while str(y) in q:
				y += 1
			q |= {str(y)}
			print(w[j][:3] + str(y))


def str_inp(n):
	return [[i, input()] for (i, x) in enumerate(range(n))]

def get_col(arr, i):
	return [row[i] for row in arr]
for i in range(int(input())):
	(dic, ans) = (dict({j: False for j in range(10)}), 0)
	arr = str_inp(int(input()))
	arr.sort(key=lambda x: x[1])
	for j in get_col(arr, 1):
		dic[int(j[0])] = True
	new = [[arr[0][0], arr[0][1]]]
	for j in range(1, len(arr)):
		tem = arr[j][1]
		if arr[j][1] == arr[j - 1][1]:
			ans += 1
			for (k1, k2) in dic.items():
				if not dic[k1]:
					tem = arr[j][1].replace(arr[j][1][0], str(k1), 1)
					dic[k1] = True
					break
		new.append([arr[j][0], tem])
	new.sort(key=lambda x: x[0])
	print(ans)
	print(*get_col(new, 1), sep='\n')


query = int(input())
for _ in range(query):
	n = int(input())
	p = [0] * n
	for i in range(n):
		p[i] = list(map(int, list(input())))
	counter = 0
	for i in range(n):
		for j in range(i):
			count = 0
			for k in range(4):
				if p[i][k] == p[j][k]:
					count += 1
			if count != 4:
				continue
			else:
				for l in range(10):
					cnt = 0
					for m in range(n):
						if p[m][0] == l:
							cnt = 1
							break
					if cnt == 1:
						continue
					else:
						p[i][0] = l
						counter += 1
						break
	print(counter)
	for i in p:
		for k in range(4):
			print(i[k], end='')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	listn = []
	for j in range(n):
		listn.append(int(input()))
	count = 0
	for j in range(n):
		if listn.count(listn[j]) > 1:
			count += 1
			listn[j] = listn[j] // 10 * 10
			while listn.count(listn[j]) > 1:
				listn[j] = listn[j] + 1
	print(count)
	for j in listn:
		print('{0:0>4}'.format(j))


from random import randint
for i in range(int(input())):
	cards_list = []
	cards = {}
	swaps = 0
	for no_of_cards in range(int(input())):
		card = input()
		cards_list.append(card)
		if card in cards:
			cards[card] += 1
			swaps += 1
		else:
			cards[card] = 1
	print(str(swaps))
	if swaps == 0:
		for (key, cards[key]) in cards.items():
			print(key)
	if swaps > 0:
		for key in list(cards):
			reps = cards[key] - 1
			new_number = key
			while reps > 0:
				while True:
					random_digit = randint(0, 3)
					my_temp_key = list(key)
					my_temp_key[random_digit] = randint(0, 9)
					new_number = ''.join((str(e) for e in my_temp_key))
					if new_number not in cards:
						reps -= 1
						cards[new_number] = 1
						loc = cards_list.index(key)
						cards_list.remove(key)
						cards_list.insert(loc, new_number)
						break
		for x in cards_list:
			print(x)


from collections import defaultdict
x = int(input())
for __ in range(x):
	n = int(input())
	d = defaultdict(list)
	s = []
	for _ in range(n):
		a = input()
		d[a].append(_)
		s.append(a)
	k = 0
	for a in range(n):
		if len(d[s[a]]) > 1:
			f = 0
			for w in d[s[a]][1:]:
				k += 1
				yo = list(s[w])
				for i in range(4):
					for j in range(0, 10):
						yo[i] = str(j)
						a = ''.join(yo)
						if len(d[a]) == 0:
							d[a].append(w)
							s[w] = a
							f = 1
							break
					if f == 1:
						break
					else:
						yo[i] = s[w][i]
	print(k)
	print('\n'.join(s))


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	all = set()
	final = [0] * n
	count = 0
	for j in range(n):
		l.append(input())
	for j in range(n):
		if l[j] in all:
			pass
		else:
			all.add(l[j])
			final[j] = l[j]
	for j in range(n):
		if final[j] == 0:
			count += 1
			for digit in range(0, 10):
				new = str(digit) + str(l[j])[1:]
				if new not in all:
					all.add(new)
					final[j] = new
					break
	print(count)
	for j in range(n):
		print(final[j])


t = int(input())
for _ in range(t):
	n = int(input())
	cards = [int(input()) for _ in range(n)]
	print(n - len(set(cards)))
	S = set()
	S.add(cards[0])
	for i in range(1, n):
		if cards[i] in S:
			l_cnt = 0
			while cards[i] in S or cards[i] in cards[i + 1:]:
				cards[i] += 1000
				if cards[i] >= 10000:
					cards[i] -= 10000
				l_cnt += 1
				if l_cnt >= 10:
					while cards[i] in S or cards[i] in cards[i + 1:]:
						cards[i] += 100
					if cards[i] >= 10000:
						cards[i] -= 10000
					l_cnt += 1
					if l_cnt >= 20:
						while cards[i] in S or cards[i] in cards[i + 1:]:
							cards[i] += 10
							if cards[i] >= 10000:
								cards[i] -= 10000
		S.add(cards[i])
	for i in range(n):
		print(str(cards[i]).zfill(4))


t = int(input())
for _ in range(t):
	n = int(input())
	d = {}
	l = []
	count = 0
	for i in range(n):
		s = input()
		d[s] = i
		l.append(s)
	for i in range(n):
		if l[i] in d:
			if d[l[i]] != i:
				count += 1
				for k in range(10):
					s = l[i]
					if s[0:3] + str(k) not in d:
						d[s[0:3] + str(k)] = i
						l[i] = s[0:3] + str(k)
						break
	print(count)
	for i in l:
		print(i)


for t in range(int(input())):
	dig = [[True for i in range(10)] for j in range(4)]
	n = int(input())
	fak = [0] * n
	A = [0] * n
	for i in range(n):
		A[i] = list(input())
		for j in range(4):
			dig[j][int(A[i][j])] = False
	for i in range(n):
		if fak[i] == 0:
			for j in range(i + 1, n):
				if A[i] == A[j]:
					fak[i] += 1
					fak[j] = -1
					k = 0
					while k < 10:
						if dig[2][k] == True:
							A[j][2] = str(k)
							dig[2][k] = False
							k = 10
						k += 1
	c = 0
	for i in range(n):
		if fak[i] > 0:
			c += fak[i]
	print(c)
	for i in range(n):
		print(A[i][0] + A[i][1] + A[i][2] + A[i][3])


t = int(input())
for u in range(t):
	n = int(input())
	a = [input() for i in range(n)]
	d = dict()
	for e in a:
		if e not in d:
			d[e] = 0
		d[e] += 1
	c = 0
	for i in range(len(a)):
		e = a[i]
		if d[e] > 1:
			c += 1
			for j in range(4):
				for k in range(10):
					p_new = e[:j] + str(k) + e[j + 1:]
					if e == p_new:
						continue
					if p_new not in d:
						new = p_new
			d[new] = 1
			d[e] -= 1
			a[i] = new
	print(c)
	for e in a:
		print(e)


t = int(input())
for _ in range(t):
	l = []
	(d, k) = ({}, 0)
	p = int(input())
	for i in range(p):
		s = input()
		l.append(s)
		if s in d:
			d[s] += 1
		else:
			d[s] = 1
			k += 1
	(s, j) = (0, '')
	l1 = [0] * 12
	se = set()
	for i in d:
		s += d[i] - 1
		j = i
		se.add(i)
		for j in range(p):
			if l[j] == i:
				l1[j] = 1
				break
	if len(d) == p:
		print(0)
		for i in range(p):
			print(l[i])
	else:
		print(s)
		for i in range(p):
			if l1[i] == 1:
				print(l[i])
				continue
			for x in range(10):
				if str(x % 10) + l[i][1:] not in se:
					print(str(x % 10) + l[i][1:])
					se.add(str(x % 10) + l[i][1:])
					break


I = input
for _ in range(int(I())):
	n = int(I())
	l = []
	d = dict()
	for _ in range(n):
		l.append(I())
	for i in range(n):
		if l[i] in d:
			d[l[i]] += 1
		else:
			d[l[i]] = 1
	c = 0
	for i in d:
		if d[i] > 0:
			c += d[i] - 1
	print(c)
	d1 = dict()
	p = []
	for i in d:
		ind = l.index(i)
		p.append([ind, i])
		for j in range(d[i] - 1):
			ind = l.index(i, ind + 1)
			for q in range(0, 10):
				t = list(i)
				t[3] = str(q)
				if ''.join(t) not in d and ''.join(t) not in d1:
					d1[''.join(t)] = 1
					p.append([ind, ''.join(t)])
					break
	p.sort(key=lambda x: x[0])
	for i in p:
		print(i[1])


import sys
input = sys.stdin.readline
t = int(input())
for zz in range(t):
	n = int(input())
	ar = [list(input().strip()) for i in range(n)]
	ans = 0
	for i in ar:
		if ar.count(i) != 1:
			ans += 1
			for t in range(10):
				i[3] = str(t)
				if ar.count(i) == 1:
					break
	print(ans)
	for i in ar:
		print(''.join(i))


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	ch = 0
	for i in range(n):
		key = 0
		for j in range(n):
			if j == i:
				continue
			if a[i] == a[j]:
				key = 1
				break
		if key == 1:
			for j in range(4):
				b = a[i][:]
				flag = 0
				for k in range(10):
					b[j] = str(k)
					if b not in a:
						ch += 1
						a[i][:] = b
						flag = 1
						break
				if flag == 1:
					break
	print(ch)
	for i in a:
		print(''.join(i))


import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		d = defaultdict(lambda : [])
		mk = {}
		ans = [0] * n
		for i in range(n):
			x = input().rstrip()
			d[x].append(i)
			ans[i] = x
			mk[x] = 1

		def get_number(x):
			for i in range(len(x)):
				for d in range(0, 10):
					y = x[:i] + str(d) + x[i + 1:]
					if y not in mk:
						mk[y] = 1
						return y
			assert 0
		changes = 0
		for (k, v) in d.items():
			while len(v) > 1:
				changes += 1
				p = v.pop()
				ans[p] = get_number(k)
			ans[v.pop()] = k
		print(changes)
		print('\n'.join(ans))
main()


def changePins():
	n = int(input())
	(arr, s) = ([], set())
	for i in range(n):
		arr.append(str(input()))
		s.add(arr[i])
	done = [0] * n
	res = 0
	for i in range(n):
		if done[i]:
			continue
		sameIds = []
		for j in range(i + 1, n):
			if arr[i] == arr[j]:
				sameIds.append(j)
				done[j] = 1
				res += 1
				k = 0
				while k < 4 and arr[i] == arr[j]:
					for c in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'):
						newCode = list(arr[j])
						newCode[k] = c
						newCode = ''.join((x for x in newCode))
						if newCode not in s:
							s.add(newCode)
							arr[j] = newCode
							break
					k += 1
	print(res)
	for i in arr:
		print(i)
t = int(input())
while t:
	changePins()
	t -= 1


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	codes = []
	for _ in range(n):
		curCode = input()
		codes.append(curCode)
	count = Counter(codes)
	seenCodes = set(codes)
	result = 0
	for (i, code) in enumerate(codes):
		if count[code] > 1:
			found = False
			for pos in range(4):
				if found:
					break
				for num in range(10):
					tempString = code[:pos] + str(num) + code[pos + 1:]
					if tempString not in seenCodes:
						seenCodes.add(tempString)
						codes[i] = tempString
						found = True
						break
			count[code] -= 1
			result += 1
	print(result)
	for code in codes:
		print(code)


for i in range(int(input())):
	n = int(input())
	s = [input() for i in range(n)]
	t = set(s)
	print(n - len(t))
	p = {}
	for i in s:
		p[i] = 0
	for i in s:
		p[i] += 1
	for i in range(n):
		if p[s[i]] == 1:
			print(s[i])
		else:
			p[s[i]] -= 1
			for j in range(10):
				r = str(j) + s[i][1:]
				if r not in p or p[r] == 0:
					s[i] = r
					p[s[i]] = 1
					break
			print(s[i])


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for x in range(n):
		l.append(input())
	count = 0
	for x in range(n):
		happen = False
		c = l[0:x] + l[x + 1:n]
		while l[x] in c:
			happen = True
			k = int(l[x][3])
			if k < 9:
				k += 1
				l[x] = l[x][0:3] + str(k)
			else:
				l[x] = l[x][0:3] + '0'
		if happen:
			happen = False
			count += 1
	print(count)
	for x in l:
		print(x)


t = int(input())
for z in range(t):
	n = int(input())
	ans = 0
	cek = [[False for z in range(10)] for x in range(4)]
	arr = []
	ans = 0
	i = 0
	while i < n:
		arr.append(list(input()))
		j = 0
		while j < 4:
			cek[j][int(arr[i][j])] = True
			j += 1
		i += 1
	h = 0
	while h < n:
		i = h + 1
		while i < n:
			if arr[h] == arr[i]:
				ans += 1
				b = True
				j = 0
				k = 0
				while j < 4 and b:
					while k < 10:
						if not cek[j][k]:
							arr[i][j] = str(k)
							cek[j][k] = True
							b = False
							break
						k += 1
					j += 1
			i += 1
		h += 1
	print(ans)
	for a in arr:
		for b in a:
			print(b, end='')
		print()


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(0, n):
		s = input()
		l.append(s)
	ans = 0
	for i in range(n):
		if l[i] in l[i + 1:n]:
			j = 0
			ans += 1
			while l[i] in l[i + 1:] + l[:i]:
				l[i] = l[i][:3] + str(j)
				j += 1
	print(ans)
	for i in range(0, n):
		print(l[i])


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		a = input().strip()
		arr.append(a)
	ans = 0
	for (i, b) in enumerate(arr):
		if arr.count(b) > 1:
			for x in '0123456789':
				arr[i] = x + b[1:]
				if arr.count(arr[i]) == 1:
					break
			ans += 1
	print(ans)
	for x in arr:
		print(x)


for _ in range(int(input())):
	n = int(input())
	arr = []
	c = 0
	s = set([])
	vis = set([])
	inds = []
	for i in range(n):
		x = input()
		arr.append(x)
		if x in vis:
			inds.append(i)
		else:
			vis.add(x)
	print(len(inds))
	for i in inds:
		ans = ''
		for j in range(10):
			ans = str(j) + arr[i][1:]
			if ans not in vis:
				vis.add(ans)
				arr[i] = ans
				break
	for i in arr:
		print(i)


t = int(input())
from collections import defaultdict
for _ in range(t):
	groups = defaultdict(list)
	n = int(input())
	cards = [input() for _ in range(n)]
	distinct = len(set(cards))
	print(n - distinct)
	for (i, x) in enumerate(cards):
		groups[x].append(i)
	not_availables = [card[0] for card in cards]
	availables = [str(i) for i in range(0, 10) if str(i) not in not_availables]
	for group in groups:
		if len(groups[group]) > 1:
			for card in groups[group][1:]:
				cards[card] = availables[-1] + cards[card][1:]
				availables.pop()
	for card in cards:
		print(card)


for i in range(int(input())):
	array = []
	j = 0
	k = 0
	n = int(input())
	used = [[], [], [], []]
	for i in range(n):
		s = list(input())
		array.append(s)
		used[0].append(s[0])
		used[1].append(s[1])
		used[2].append(s[2])
		used[3].append(s[3])
	ans = []
	array.append(1)
	t = 0
	for i in range(len(array) - 1):
		if array[i] in array[0:i] or array[i] in array[i + 1:len(array)]:
			if '0' not in used[0]:
				array[i][0] = '0'
				used[0].append('0')
			elif '1' not in used[0]:
				array[i][0] = '1'
				used[0].append('1')
			elif '2' not in used[0]:
				array[i][0] = '2'
				used[0].append('2')
			elif '3' not in used[0]:
				array[i][0] = '3'
				used[0].append('3')
			elif '4' not in used[0]:
				array[i][0] = '4'
				used[0].append('4')
			elif '5' not in used[0]:
				array[i][0] = '5'
				used[0].append('5')
			elif '6' not in used[0]:
				array[i][0] = '6'
				used[0].append('6')
			elif '7' not in used[0]:
				array[i][0] = '7'
				used[0].append('7')
			elif '9' not in used[0]:
				array[i][0] = '9'
				used[0].append('9')
			elif '8' not in used[0]:
				array[i][0] = '8'
				used[0].append('8')
			else:
				k += 1
				array[i][1] == k
			j += 1
			ans.append(array[i])
		else:
			ans.append(array[i])
	print(j)
	for i in range(len(ans)):
		print(*ans[i], sep='')


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		P = []
		for _ in range(N):
			P.append(input().strip())
		ans = []
		ans.append(P[0])
		count = 0
		for i in range(1, N):
			if P[i] in ans:
				count += 1
				for j in range(0, 10):
					x = str(j) + P[i][1:]
					if j == N - 1:
						if x not in ans:
							ans.append(x)
							break
					elif x not in ans and x not in P[i + 1:]:
						ans.append(x)
						break
			else:
				ans.append(P[i])
		print(count)
		for a in ans:
			print(a)
main()


import sys
from collections import Counter
input = sys.stdin.readline
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
t = int(input())
for i in range(t):
	n = int(input())
	pincode = []
	for j in range(n):
		pincode.append(input().rstrip())
	cnt = Counter(pincode)
	seen = set(pincode)
	ans = 0
	ret = []
	for (i, pin) in enumerate(pincode):
		if cnt[pin] == 1:
			ret.append(pin)
			continue
		ans += 1
		ok = False
		for k in range(10):
			nkey = number[k] + pin[1:]
			if nkey not in seen:
				seen.add(nkey)
				ret.append(nkey)
				cnt[pin] -= 1
				ok = True
				break
		if ok:
			continue
		for k in range(10):
			nkey = pin[0] + number[k] + pin[2:]
			if nkey not in seen:
				seen.add(nkey)
				ret.append(nkey)
				cnt[pin] -= 1
				ok = True
				break
		if ok:
			continue
	print(ans)
	for item in ret:
		print(item)


t = int(input().strip())

def change(listt):
	a = 0
	while a in listt:
		a += 1
	return a
for i in range(t):
	n = int(input().strip())
	pins = []
	for j in range(n):
		pins.append(input().strip())
	pins_set = set(pins)
	if len(pins_set) == n:
		num = 0
	else:
		num = 0
		p0 = {int(h[0]) for h in pins}
		for ps in pins_set:
			it = pins.count(ps) - 1
			num += it
			for k in range(it):
				ind = pins.index(ps)
				dif = change(p0)
				p0.add(dif)
				pins[ind] = str(dif) + pins[ind][1:]
	print(num)
	for p in pins:
		print(p)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	n = ii()
	res = [''] * n
	d = []
	for i in range(n):
		pin = input()
		if pin in res:
			d.append((i, pin))
			continue
		res[i] = pin
	for tup in d:
		(pos, pin) = tup
		for i in range(4):
			h = pin[:i]
			t = pin[i + 1:]
			for j in '0123456789':
				new = f'{h}{j}{t}'
				if new not in res:
					res[pos] = new
					break
			if res[pos]:
				break
	print(len(d))
	prr(res, '\n')


t = int(input())
for sad in range(t):
	n = int(input())
	pin = list()
	inside = set()
	first = set()
	for i in range(10):
		first.add(i)
	for i in range(n):
		s = input()
		if s not in inside:
			pin.append([list(s), 0])
			inside.add(s)
			first.discard(int(s[0]))
		else:
			pin.append([list(s), 1])
	ans = 0
	for i in range(n):
		if pin[i][1] == 1:
			for k in first:
				pin[i][0][0] = k
				first.remove(k)
				ans += 1
				break
	print(ans)
	for i in range(n):
		print(*pin[i][0], end='', sep='')
		print()


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import permutations
from copy import deepcopy
from heapq import *

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	for _ in range(int(input())):
		n = int(input())
		a = []
		b = Counter()
		for i in range(n):
			a.append(input().rstrip())
			b[a[-1]] += 1
		y = 0
		for i in range(n):
			if b[a[i]] > 1:
				b[a[i]] -= 1
				for j in range(4):
					(z, f) = (list(a[i]), 0)
					for k in '0123456789':
						z[j] = k
						x = ''.join(z)
						if b[x] == 0:
							y += 1
							(f, a[i], b[x]) = (1, x, 1)
							break
					if f:
						break
		print(y)
		for i in a:
			print(i)
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')
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		z = []
		d = {}
		for i in range(n):
			s = rs()
			z.append(tuple(s))
			if z[-1] in d:
				d[z[-1]] += 1
			else:
				d[z[-1]] = 1
		p = []
		nd = {}
		for i in d:
			p.append(i)
			if i not in nd:
				nd[i] = []
		yo = 0
		ans2 = []
		for i in p:
			yo += d[i] - 1
			nd[i].append(list(i))
			for j in range(d[i] - 1):
				d[i] -= 1
				q = list(i)
				lol = 0
				for k in range(4):
					e = q[k]
					for h in range(9):
						q[k] = chr(48 + h)
						if tuple(q) not in d:
							lol = 101
							d[tuple(q)] = 1
							nd[i].append(list(q))
							break
						else:
							q[k] = e
					if lol == 101:
						break
		print(yo)
		for i in z:
			ans = ''
			kk = nd[i][-1]
			nd[i].pop()
			for j in kk:
				ans += j
			print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = [input() for i in range(N)]
	C = Counter(A)
	cnt = 0
	for i in range(N):
		if C[A[i]] > 1:
			cnt += 1
			prev = A[i]
			while C[A[i]] > 0:
				a = int(A[i][0])
				a += 1
				a %= 10
				A[i] = str(a) + A[i][1:]
			C[A[i]] += 1
			C[prev] -= 1
	print(cnt)
	[print(a) for a in A]


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(input())
	ans = 0
	for i in range(n):
		if arr[i] in arr[i + 1:]:
			ans += 1
			j = 0
			while arr[i] in arr[i + 1:] + arr[:i]:
				arr[i] = arr[i][:3] + str(j)
				j += 1
	print(ans)
	for i in range(n):
		print(arr[i])


import random

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = []
		for _ in range(n):
			arr.append(input())
		ans = 0
		for i in range(n):
			if arr[i] in arr[i + 1:]:
				ans += 1
				j = 0
				while arr[i] in arr[i + 1:] + arr[:i]:
					arr[i] = arr[i][:3] + str(j)
					j += 1
		print(ans)
		for i in range(n):
			print(arr[i])
main()


def solve():
	n = int(input())
	a = []
	h = set()
	c = [False for _ in range(n)]
	res = 0
	for _ in range(n):
		pin = input()
		a.append(pin)
		h.add(pin)
	for i in range(n):
		if c[i]:
			continue
		for j in range(i + 1, n):
			if a[i] == a[j]:
				res += 1
				c[j] = True
				for k in range(4):
					if a[j] != a[i]:
						break
					for d in range(ord('0'), ord('9')):
						d = chr(d)
						t = a[j]
						t = t[:k] + d + t[k + 1:]
						if t not in h:
							a[j] = t
							h.add(t)
							break
	print(res)
	print('\n'.join(a))
t = int(input())
for _ in range(t):
	solve()


from copy import deepcopy
for _ in range(int(input())):
	n = int(input())
	a = [list(map(int, list(input()))) for _ in range(n)]
	t = deepcopy(a)
	for i in range(1, n):
		pin = t[i]
		while t.count(pin) > 1:
			pin[0] = (pin[0] + 1) % 10
	cnt = sum([a[i] != t[i] for i in range(n)])
	print('%d\n%s' % (cnt, '\n'.join((''.join(map(str, pin)) for pin in t))))


t = int(input())
for i in range(t):
	(s, l) = ([], [])
	count = 0
	n = int(input())
	for j in range(n):
		l.append(input())
		s.append(int(l[j][0]))
	for j in range(n):
		for i in range(j + 1, n):
			if l[j] == l[i]:
				for k in range(10):
					if k not in s:
						s.append(k)
						l[j] = f'{k}' + l[j][1:]
						count += 1
						break
	print(count)
	for i in range(n):
		print(l[i])


for t in range(int(input())):
	n = int(input())
	l = [input() for x in range(n)]
	k = len(set(l))
	if n == k:
		print(0)
		print(*l, sep='\n')
		continue
	print(n - k)
	for i in range(n):
		if l[i] in l[i + 1:]:
			j = 0
			while l[i] in l[i + 1:] + l[:i]:
				l[i] = l[i][:3] + str(j)
				j += 1
	print(*l, sep='\n')


for _ in range(int(input())):
	n = int(input())
	d = dict()
	c = []
	for i in range(n):
		x = input()
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
		c.append(x)
	ans = 0
	for i in d:
		ans += d[i] - 1
	ansa = []
	for i in range(n):
		if d[c[i]] == 1:
			ansa.append(c[i])
			continue
		for j in range(10):
			x = f'{j}' + c[i][1:]
			if x not in d:
				d[c[i]] -= 1
				d[x] = 1
				ansa.append(x)
				break
	print(ans)
	for i in range(n):
		print(ansa[i])


T = int(input())
for t in range(T):
	N = int(input())
	Ans = [0] * N
	coll = []
	V = set()
	for n in range(N):
		s = input().strip()
		if s in V:
			coll.append((s, n))
		Ans[n] = s
		V.add(s)
	for (c, pos) in coll:
		for i in range(4):
			tVal = int(c[i])
			for j in range(1, 10):
				c = c[:i] + str((tVal + j) % 10) + c[i + 1:]
				if c not in V:
					V.add(c)
					break
			else:
				c = c[:i] + str(tVal) + c[i + 1:]
				continue
			break
		Ans[pos] = c
	print(len(coll), *Ans, sep='\n')


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		n = inin()
		a = []
		d = {}
		for i in range(n):
			s = inin()
			a.append(s)
			if s in d:
				d[s] += 1
			else:
				d[s] = 1
		x = []
		ans = 0
		e = {}
		for i in d:
			ans += d[i] - 1
			j = 1
			jj = 1
			e[i] = [i]
			while j < d[i]:
				f = i // 10
				if f * 10 + (i + jj) % 10 not in d:
					e[i].append(f * 10 + (i + jj) % 10)
					j += 1
				jj += 1
		print(ans)
		for j in a:
			i = e[j].pop()
			i = str(i)
			for j in range(4 - len(i)):
				print(0, end='')
			print(i)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


from collections import defaultdict as dd
t = int(input())
while t:
	d = dd(list)
	nd = dd(int)
	res = []
	se = set()
	n = int(input())
	cou = 0
	for i in range(n):
		s = input()
		d[s].append(i)
		se.add(s)
		nd[s] = 1
	for j in d:
		ll = len(d[j])
		res.append((d[j][0], str(j)))
		ss = str(j)[:3]
		for k in range(1, ll):
			cou += 1
			for ii in range(10):
				if nd[ss + str(ii)] == 0:
					se.add(ss + str(ii))
					res.append((d[j][k], ss + str(ii)))
					nd[ss + str(ii)] += 1
					break
	print(cou)
	res.sort()
	for v in res:
		print(v[1])
	t -= 1


tc = int(input())
for _ in range(tc):
	n = int(input())
	dic = {}
	l = []
	ans = 0
	for i in range(n):
		l.append(input())
	for i in range(n):
		if l[i] in l[i + 1:]:
			ans += 1
			j = 0
			while l[i] in l[i + 1:] + l[:i]:
				l[i] = l[i][:3] + str(j)
				j += 1
	print(ans)
	for x in l:
		print(x)


def run_length_compress(string):
	string.append('@')
	n = len(string)
	begin = 0
	end = 1
	cnt = 1
	ans = []
	while True:
		if end >= n:
			break
		if string[begin] == string[end]:
			end += 1
			cnt += 1
		else:
			ans.append((cnt, string[begin]))
			begin = end
			end = begin + 1
			cnt = 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	p = [input() for i in range(n)]
	set_ = set([])
	init_set = set([])
	for i in range(n):
		init_set.add(p[i])
	ans_num = 0
	ans = []
	for i in range(n):
		flag = False
		if p[i] not in set_ and p[i] in init_set:
			ans.append(p[i])
			set_.add(p[i])
			continue
		while True:
			if p[i] not in set_ and p[i] not in init_set:
				ans.append(p[i])
				set_.add(p[i])
				if flag:
					ans_num += 1
				break
			else:
				p[i] = str((int(p[i][0]) + 1) % 10) + p[i][1:]
				flag = True
	print(ans_num)
	for i in ans:
		print(i)


from collections import Counter

def get_numbers(s):
	r = set()
	for i in range(0, 10):
		for j in range(0, 4):
			t = list(s)
			t[j] = str(i)
			r.add(''.join(t))
	r.remove(s)
	return r
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	inp = []
	for _ in range(n):
		inp.append(input())
	c = Counter(inp)
	arr = set(inp)
	arr1 = Counter(set(inp))
	ans = []
	for s in inp:
		if s in arr1:
			arr1 -= Counter({s: 1})
			ans.append(s)
			arr.add(s)
			continue
		if s in arr:
			e = list(get_numbers(s) - arr)[0]
			arr.add(e)
			ans.append(e)
			cnt += 1
		else:
			arr += Counter({s: 1})
	print(cnt)
	for a in ans:
		print(a)


import math

def find_nz(b):
	for i in range(4):
		for j in range(10):
			if b[i][j] != 1:
				return (i, j)
n = int(input())
for idx in range(n):
	t = int(input())
	l = []
	for j in range(t):
		l.append(input())
	s = {}
	for i in range(len(l)):
		s[l[i]] = 0
	for i in range(len(l)):
		s[l[i]] += 1
	occ = [[0 for i in range(10)] for j in range(4)]
	for sth in s:
		for i in range(4):
			occ[i][int(sth[i])] = 1
	change = 0
	for sth in s:
		change += s[sth] - 1
	print(change)
	for sth in s:
		c = s[sth] - 1
		for i in range(c):
			for j in range(len(l)):
				if l[j] == sth:
					(a, b) = find_nz(occ)
					ns = ''
					for sidx in range(len(sth)):
						if sidx != a:
							ns += sth[sidx]
						else:
							ns += str(b)
					occ[a][b] = 1
					l[j] = ns
					break
	for sth in l:
		print(sth)


t = int(input())
for ij in range(0, t):
	n = int(input())
	l = []
	ans = 0
	la = []
	li = []
	for i in range(0, n):
		s = input()
		la.append(s)
		if s in l:
			ans += 1
			li.append(i)
		else:
			l.append(s)
	print(ans)
	for i in li:
		s = la[i]
		for k in range(0, 4):
			t = 0
			for j in range(0, 10):
				s1 = s[:k] + str(j) + s[k + 1:]
				if s1 not in l:
					l.append(s1)
					la[i] = s1
					t = 1
					break
			if t == 1:
				break
	for i in la:
		print(i)


from __future__ import print_function
import collections
import copy

def change(p, have):
	p = list(p)
	for i in range(4):
		for j in range(10):
			pp = copy.copy(p)
			pp[i] = str(j)
			if ''.join(pp) not in have:
				return ''.join(pp)
	assert False
T = int(input())
for _ in range(T):
	n = int(input())
	s = []
	res = []
	cnt = collections.defaultdict(int)
	for _ in range(n):
		s.append(input())
		cnt[s[-1]] += 1
	S = set(s)
	print(n - len(S))
	have = set()
	for p in s:
		if p not in have:
			print(p)
			have.add(p)
		else:
			pp = change(p, have | S)
			print(pp)
			have.add(pp)


t = int(input())
for _ in range(t):
	n = int(input())
	p = [input() for _ in range(n)]
	change = 0
	s = set()
	for i in range(n):
		if p[i] in s:
			for j in range(10):
				if not str(j) + p[i][1:] in p:
					change += 1
					p[i] = str(j) + p[i][1:]
					break
		s.add(p[i])
	print(change)
	for pi in p:
		print(pi)


from collections import deque
t = int(input())
L = []
for _ in range(t):
	n = int(input())
	temp = [int(n)]
	for _ in range(n):
		temp.append(str(input()))
	L.append(temp)
for i in range(t):
	cnt = 0
	n = L[i][0]
	L_ = deque(L[i][1:n + 1])
	for _ in range(n):
		temp = L_.popleft()
		if temp in L_:
			temp = list(temp)
			for k in range(10):
				temp[3] = str(k)
				temp = ''.join(temp)
				if temp not in L_:
					cnt += 1
					L_.append(temp)
					break
				else:
					temp = list(temp)
		else:
			L_.append(temp)
	print(cnt)
	for l in L_:
		print(l)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	p = set()
	ct = 0
	freq = {}
	st = []
	for i in range(n):
		s = sys.stdin.readline().strip()
		if s not in freq:
			freq[s] = 0
		freq[s] += 1
		st.append(s)
	used = set()
	for s in st:
		if freq[s] == 1 or s not in p:
			p.add(s)
		else:
			ct += 1
			for i in range(4):
				f = False
				for digit in range(10):
					ns = s[:i] + str(digit) + s[i + 1:]
					if ns not in freq:
						f = True
						p.add(ns)
						freq[ns] = 1
						break
				if f:
					break
	print(ct)
	for i in p:
		print(i)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(input()))
	ans = 0

	def minimize(i):
		l2 = ''.join((k[i] for k in a))
		for p in range(10):
			x = str(p)
			if x not in l2:
				return x
	for i in range(4):
		di = {}
		for j in range(len(a)):
			el = a[j]
			if el[i] not in di:
				di[el[i]] = j
			elif a[di[el[i]]] == el:
				ans += 1
				a[j][i] = minimize(i)
			else:
				continue
	print(ans)
	for x in a:
		print(''.join(x))


ls_digit = []
ans_num = 0
ans_ls = []
ans_nls = []
nls = []
cnt = 0
t = int(input())
for i in range(t):
	ans_num = 0
	n = int(input())
	nls.append(n)
	for j in range(n):
		cnt = 0
		a = int(input())
		ls_digit.append(a)
	for k in range(len(ls_digit) - 1):
		if ls_digit.count(ls_digit[k]) > 1:
			ans_num += 1
		while ls_digit.count(ls_digit[k]) > 1:
			ls_digit[k] += 1
			if ls_digit[k] % 10 == 0:
				ls_digit[k] -= 10
	ans_nls.append(ans_num)
	for j in ls_digit:
		ans_ls.append(j)
	ls_digit = []
for i in range(t):
	print(ans_nls[i])
	for j in ans_ls[sum(nls[0:i]):sum(nls[0:i + 1])]:
		print('{:0=4}'.format(j))


for i in range(int(input())):
	numbers = []
	size = int(input())
	for _ in range(size):
		numbers.append(int(input()))
	change = size - len(set(numbers))
	unique = []
	uni_dig = 0
	while len(numbers):
		num = numbers.pop()
		while num in unique or num in numbers:
			num = num // 10 * 10 + uni_dig
			uni_dig = (uni_dig + 1) % 10
		unique.append(num)
	print(change)
	for num in reversed(unique):
		print('{0:-04}'.format(num))


t = int(input())

def counter(a, num):
	v = 0
	for i in a:
		if i == num:
			v += 1
	return v
for _ in range(t):
	n = int(input())
	nums = []
	for _ in range(n):
		nums.append(list(input().strip()))
	ret_val = 0
	for num in nums:
		c = counter(nums, num)
		if c != 1:
			ret_val += 1
			for k in range(10):
				num[3] = str(k)
				cc = counter(nums, num)
				if cc == 1:
					break
	print(ret_val)
	for i in nums:
		print(''.join(i))


def main():
	n = int(input())
	for i in range(n):
		c = int(input())
		data = [input() for v in range(c)]
		freq = {}
		for d in data:
			if d not in freq:
				freq[d] = 0
			freq[d] += 1
		print(sum([v - 1 for v in freq.values()]))
		vals = set()
		for d in data:
			if freq[d] > 1:
				for v in newd(d):
					if v not in freq and v not in vals:
						vals.add(v)
						print(v)
						freq[d] -= 1
						break
			else:
				vals.add(d)
				print(d)

def newd(d):
	for i in range(0, 4):
		for j in range(0, 11):
			v = d[:i] + str(j) + d[i + 1:]
			yield v
main()


t = int(input())
for i in range(t):
	cards = int(input())
	v1 = []
	for i in range(cards):
		v1.append(input())
	d1 = dict()
	for val in v1:
		if val not in d1:
			d1[val] = 1
		else:
			d1[val] += 1
	print(len(v1) - len(d1))
	for i in range(len(v1)):
		old = v1[i]
		if d1[old] > 1:
			while v1[i] in d1:
				v1[i] = str((int(v1[i][0]) + 1) % 10) + v1[i][1:]
		d1[old] -= 1
		d1[v1[i]] = 1
		print(v1[i])


for _ in range(int(input())):
	n = int(input())
	l = [int(input()) for a in range(n)]
	ans = 0
	for i in range(n):
		if l[i] in l[i + 1:]:
			ans += 1
			while l[i] in l[i + 1:] + l[:i]:
				l[i] += 1000
				l[i] %= 10000
	print(ans)
	for i in l:
		print('%04d' % i)


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase():
	for p in range(int(inp())):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	a = []
	for i in range(0, n):
		a.append(inp())
	lastdigit = set([])
	for i in range(0, n):
		lastdigit.add(a[i][3])
	changes = 0
	for i in range(0, n):
		for j in range(i + 1, n):
			if a[i] == a[j]:
				changes += 1
				for k in range(0, 10):
					if str(k) not in lastdigit:
						a[j] = a[j][:3] + str(k)
						lastdigit.add(str(k))
						break
	out(changes)
	nextline()
	for i in range(0, n):
		out(a[i])
		nextline()
testcase()


from sys import stdin, stdout
casos = int(stdin.readline().strip())
for case in range(casos):
	n = int(stdin.readline().strip())
	s = [list(stdin.readline().strip()) for j in range(n)]
	ans = 0
	for i in range(n):
		if s.count(s[i]) == 1:
			continue
		else:
			ans += 1
			flag = False
			for j in range(4):
				s1 = s[i].copy()
				for k in range(10):
					aux = s1[j]
					s1[j] = str(k)
					if s.count(s1) == 0:
						flag = True
						s[i] = s1
						break
					s1[j] = aux
				if flag:
					break
	stdout.write('%d\n' % ans)
	for i in s:
		aux = ''
		for j in i:
			aux += j
		stdout.write('%s\n' % aux)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = [list(map(int, input())) for _ in range(n)]
	cnt = Counter([''.join(map(str, pin)) for pin in a])
	ans = 0
	for i in range(n):
		if cnt[''.join(map(str, a[i]))] > 1:
			ans += 1
		while cnt[''.join(map(str, a[i]))] > 1:
			cnt[''.join(map(str, a[i]))] -= 1
			a[i][0] = (a[i][0] + 1) % 10
			cnt[''.join(map(str, a[i]))] += 1
	print(ans)
	for pin in a:
		print(*pin, sep='')


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	d = {}
	a = []
	for i in range(n):
		s = input()
		if s not in d:
			d[s] = 0
		d[s] += 1
		a.append(s)
	ans = 0
	nums = set([i for i in range(10)])
	for i in range(n):
		if d[a[i]] > 1:
			t = list(a[i])
			for j in range(4):
				fl = False
				for k in range(10):
					t[j] = str(k)
					ns = ''.join(t)
					if ns not in d:
						d[a[i]] -= 1
						if d[a[i]] == 0:
							d.pop(a[i])
						a[i] = ns
						fl = True
						d[ns] = 1
						ans += 1
						break
				if fl:
					break
				t[j] = a[j]
	print(ans)
	for i in a:
		print(i)


for _ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(n):
		s = input()
		d = list(s)
		ar.append(d)
	b = []
	for i in range(10):
		for j in range(n):
			if str(i) == ar[j][0]:
				b.append(str(i))
	br = set(b)
	a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
	a = a - br
	mr = list(a)
	y = 0
	for i in range(n):
		for j in range(i + 1, n):
			if ar[i] == ar[j]:
				ar[j][0] = mr[y]
				y = y + 1
	print(y)
	for i in ar:
		print(''.join(i))


t = int(input())
total = []
changes = []
for ti in range(t):
	n = int(input())
	change = 0
	digits = {'0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1}
	pins = []
	for i in range(n):
		pin = list(input())
		pins.append(pin)
		if pin[0] in digits:
			digits.pop(pin[0])
	digits = list(digits.keys())
	if len(digits) > 0:
		pins_dict = {}
		for i in range(n):
			if ''.join(pins[i]) in pins_dict:
				pins[i][0] = digits.pop()
				change += 1
				pins_dict[''.join(pins[i])] = 1
			else:
				pins_dict[''.join(pins[i])] = 1
	print(change)
	for p in pins:
		print(''.join(p))


for _ in ' ' * int(input()):
	a = int(input())
	k = [[0] * 10 for _ in ' ' * 4]
	z = []
	for _ in ' ' * a:
		b = list(map(int, input().replace('', ' ').split()))
		for (i, j) in enumerate(b):
			k[i][j] = 1
		z.append(b)
	ans = 0
	for x in range(a):
		if z.count(z[x]) != 1:
			f = z[x].copy()
			ok = 0
			for i in range(4):
				for j in range(10):
					if k[i][j] == 0:
						p = f.copy()
						p[i] = j
						if p not in z:
							ok = 1
							z[x] = p
							ans += 1
							break
					if ok:
						break
				if ok:
					break
	print(ans)
	for i in z:
		print(*i, sep='')


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for i in range(n):
		b = str(input())
		a.append(b)
	p = 0
	for j in range(n):
		if a.count(a[j]) > 1:
			p += 1
			q = a[j][3]
			y = 0
			while y < 10:
				if a.count(a[j][0:3] + str(y)) == 0:
					a[j] = a[j][0:3] + str(y)
					y = 100
				y += 1
	print(p)
	for w in range(n):
		print(a[w])


import math

def change(p, n):
	digit = n // 10
	add = n % 10
	newdigit = str((int(p[digit]) + add) % 10)
	if digit == 0:
		return newdigit + p[1:]
	elif digit == 1:
		return p[0] + newdigit + p[2:]
	elif digit == 2:
		return p[:1] + newdigit + p[3]
	elif digit == 3:
		return p[:3] + newdigit

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		occ = dict()
		result = []
		for j in range(n):
			p = str(input())
			if p not in occ:
				occ[p] = 1
			else:
				occ[p] += 1
			result.append(p)
		modify = 0
		newresult = []
		for pin in result:
			occ[pin] -= 1
			if occ[pin] > 0:
				for diff in range(40):
					newpin = change(pin, diff)
					if newpin not in occ:
						occ[newpin] = 1
						newresult.append(newpin)
						break
				modify += 1
			else:
				newresult.append(pin)
		print(modify)
		print('\n'.join(newresult))
main()


for __ in range(int(input())):
	n = int(input())
	s = set()
	d = dict()
	gg = dict()
	for _ in range(n):
		ss = input().strip()
		s.add(ss)
		if ss not in d:
			d[ss] = 1
			gg[ss] = [_]
		else:
			gg[ss].append(_)
			d[ss] += 1
	ans = [0] * n
	print(n - len(s))
	for i in s:
		ans[gg[i][0]] = i
		for g in range(1, d[i]):
			for co in range(10):
				new = i[:3] + str(co)
				if new not in d:
					d[new] = 1
					ans[gg[i][g]] = new
					break
	for i in range(n):
		print(ans[i])


from sys import stdin

def operate():
	cards = int(fin.readline().rstrip())
	checkset = {i for i in range(10)}
	cardoc = {}
	waiting = []
	ready = {}
	changes = 0
	for i in range(cards):
		a = fin.readline().rstrip()
		b = a[1:]
		if b not in cardoc or int(a[0]) not in cardoc[b]:
			ready[i] = a
			try:
				cardoc[b].add(int(a[0]))
			except:
				cardoc[b] = {int(a[0])}
		else:
			changes += 1
			waiting.append((b, i))
	for i in waiting:
		b = i[0]
		c = min(checkset - cardoc[b])
		cardoc[b].add(c)
		ready[i[1]] = str(c) + b
	print(changes)
	for i in range(cards):
		print(ready[i])
with stdin as fin:
	tests = int(fin.readline().rstrip())
	for i in range(tests):
		operate()


from collections import Counter

def main():
	for _ in range(int(input())):
		l = [input() for _ in range(int(input()))]
		(cnt, c) = (Counter(l), 0)
		for (i, w) in enumerate(l):
			if cnt[w] > 1:

				def helper(w):
					cnt[w] -= 1
					for i in range(4):
						t = list(w)
						for d in '0123456789':
							t[i] = d
							u = ''.join(t)
							if u not in cnt:
								cnt[u] = 1
								return u
				l[i] = helper(w)
				c += 1
		print(c, *l, sep='\n')
main()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	d = {}
	a = []
	for i in range(n):
		s = input()
		a.append(str(s))
		if str(s) not in d:
			d[str(s)] = 1
		else:
			d[str(s)] += 1
	c = 0
	for i in range(n):
		if d[a[i]] > 1:
			p = a[i]
			d[p] -= 1
			while p in d:
				p = list(p)
				p[0] = str((int(p[0]) + 1) % 10)
				p = ''.join(p)
			d[p] = 1
			a[i] = p
			c += 1
	print(c)
	for i in range(n):
		print(a[i])


t = int(input())
for _ in range(t):
	n = int(input())
	vis = set()
	it = [input() for i in range(n)]
	ss = {}
	ans = []
	j = 0
	for i in it:
		try:
			ss[i].append(j)
		except:
			ss[i] = [j]
		j += 1
	tot = 0
	x = list(ss.keys())[:]
	for i in x:
		if len(ss[i]) == 1:
			continue
		for kk in ss[i][1:]:
			for jj in range(10):
				j = i
				j = j[:3] + str(jj)
				try:
					x = ss[j]
				except:
					tot += 1
					ss[j] = [kk]
					break
		ss[i] = [ss[i][0]]
	for i in ss:
		ans.append([i, ss[i][0]])
	ans.sort(key=lambda x: x[1])
	print(tot)
	for i in ans:
		print(i[0])


q = int(input())
for i in range(q):
	n = int(input())
	d = dict()
	curr = []
	nums = []
	res = 0
	for j in range(n):
		a = int(input())
		if a in d:
			res += 1
			curr.append(a)
			nums.append(-1)
		else:
			d[a] = 1
			nums.append('000' + str(a))
	el = 0
	cifra = 0
	while el < len(curr):
		if cifra * 1000 + curr[el] % 1000 not in d:
			d[cifra * 1000 + curr[el] % 1000] = 1
			curr[el] = '000' + str(cifra * 1000 + curr[el] % 1000)
			cifra = 0
			el += 1
		else:
			cifra += 1
	print(res)
	c = 0
	for j in range(n):
		if nums[j] == -1:
			s = curr[c]
			print(s[len(s) - 4:])
			c += 1
		else:
			s = nums[j]
			print(s[len(s) - 4:])


for _ in range(int(input())):
	n = int(input())
	dic = {}
	l1 = []
	for i in range(n):
		z = input()
		dic.setdefault(z, 0)
		dic[z] += 1
		l1.append(z)
	i = 0
	cnt = 0
	while i < n:
		tc = l1[i]
		k = 0
		while tc in dic.keys() and dic[tc] > 1:
			dic[tc] -= 1
			cnt += 1
			ind = l1.index(tc)
			temp = f'{k}' + l1[ind][1:]
			if temp in l1:
				k += 1
				dic[tc] += 1
				cnt -= 1
				continue
			else:
				l1[ind] = temp
			k += 1
		i += 1
	print(cnt)
	print('\n'.join(l1))


import sys

def I():
	return sys.stdin.readline().rstrip()
for _ in range(int(I())):
	n = int(I())
	c = 0
	l = [I() for _ in range(n)]
	r = []
	for s in l:
		if s in r:
			c += 1
			for i in range(10):
				sn = s[:-1] + chr(ord('0') + i)
				if sn not in l and sn not in r:
					s = sn
					break
		r.append(s)
	print(c)
	for s in r:
		print(s)


from collections import *
for u in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	c = 0
	for i in l:
		f = 0
		for j in range(10):
			if l.count(i) == 1:
				break
			i[-1] = str(j)
			f = 1
		c += f
	print(c)
	for i in l:
		print(''.join(i))


t = int(input())
for _ in range(t):
	n = int(input())
	l = [input() for i in range(n)]
	l2 = 10000 * [0]
	s1 = set([int(e[0]) for e in l])
	s2 = set([int(e) for e in l])
	if len(s2) == n:
		print(0)
		for e in l:
			print(e)
	else:
		print(n - len(s2))
		for e in l:
			if l2[int(e)] == 0:
				print(e)
				l2[int(e)] += 1
			else:
				for i in range(10):
					if i not in s1:
						print(str(i) + e[1:])
						s1.add(i)
						break


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	p = []
	for i in range(n):
		p.append(sinput())
	c = 0
	for i in range(n):
		flag = 0
		j = 0
		while p[i] in p[i + 1:] + p[:i]:
			flag = 1
			p[i] = str(j) + p[i][1:]
			j += 1
		if flag:
			c += 1
	print(c)
	for e in p:
		print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	ori = []
	for _ in range(n):
		ori.append(input())
	orignal = []
	arr = []
	for i in ori:
		arr.append(list(i))
		orignal.append(list(i))
	for i in range(n):
		for j in range(i + 1, n):
			if arr[i] == arr[j]:
				flag = 1
				while flag:
					if arr[j][3] != '9':
						arr[j][3] = str(int(arr[j][3]) + 1)
					else:
						arr[j][3] = '0'
					k = 0
					while k < n:
						if arr[k] == arr[j] and k != j:
							break
						k += 1
					if k == n:
						flag = 0
	c = 0
	for i in range(n):
		if arr[i] != orignal[i]:
			c += 1
	print(c)
	for j in arr:
		print(''.join(j))


q = int(input())
for i in range(q):
	n = int(input())
	pins = []
	for j in range(n):
		pins.append(input())
	changes = n - len(set(pins))
	for j in range(n):
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
		if pins.count(pins[j]) == 1:
			continue
		if pins[j][0] == '9':
			pins[j] = '0' + pins[j][1:]
		else:
			pins[j] = str(int(pins[j][0]) + 1) + pins[j][1:]
	print(changes)
	for j in pins:
		print(j)


for p in range(0, int(input())):
	n = int(input())
	pins = []
	rep = {}
	norep = []
	cont = []
	nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(0, n):
		pins.append(input())
	for i in pins:
		if i not in norep:
			norep.append(i)
		else:
			rep[i] = 0
			cont.append(i)
	for i in range(0, len(pins)):
		if pins[i][3] in nums:
			nums.remove(pins[i][3])
	if len(norep) == len(pins):
		print(0)
		for i in range(0, len(pins)):
			print(pins[i])
	else:
		print(len(cont))
		for i in range(0, len(pins)):
			if pins[i] in rep and rep[pins[i]] == 0:
				rep[pins[i]] += 1
				print(pins[i])
			elif pins[i] in rep and rep[pins[i]] > 0:
				rep[pins[i]] += 1
				for j in range(0, 3):
					print(pins[i][j], end='')
				print(nums[0])
				nums.pop(0)
			else:
				print(pins[i])


def pplus(lista, a, b):
	lista[a] = b
tcs = int(input())
for _ in range(tcs):
	n = int(input())
	num = []
	chk = dict()
	for i in range(n):
		num.append(list(map(int, list(str(input())))))
		chk[tuple(num[i])] = 1
	res = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if num[i] == num[j]:
				flag = False
				for k in range(4):
					for s in range(10):
						pplus(num[j], k, s)
						if chk.get(tuple(num[j])) == None:
							chk[tuple(num[j])] = 1
							flag = True
							break
						else:
							pplus(num[j], k, num[i][k])
					if flag:
						res += 1
						break
	print(res)
	for i in range(n):
		for j in range(4):
			print(num[i][j], end='')
		print()


t = int(input())
for I in range(t):
	n = int(input())
	a = [''] * n
	for i in range(n):
		a[i] = input()
	b = [[] for i in range(n)]
	for i in range(n):
		for j in range(i):
			if a[j] == a[i]:
				b[i].append(j)
				break
	new = [a[i] for i in range(n)]
	digits = [False] * 10
	ans = sum([1 if len(b[i]) > 0 else 0 for i in range(n)])
	print(ans)
	for i in range(n):
		if len(b[i]) == 0:
			digits[int(a[i][0])] = True
	for i in range(n):
		if len(b[i]) > 0:
			ind = digits.index(False)
			new[i] = str(ind) + a[i][1:]
			digits[ind] = True
		print(new[i])


for _ in range(int(input())):
	n = int(input())
	pins = []
	for i in range(n):
		pins.append(list(map(str, input())))
	reslt = 0
	(i, j, k) = (0, 0, 0)
	same = False
	while i < n:
		j = 0
		while j < n:
			if i != j and pins[i] == pins[j]:
				same = True
				reslt += 1
				break
			j += 1
		if same:
			k = 0
			while k <= 9:
				j = 0
				pins[i][-1] = str(k)
				done = True
				while j < n:
					if i != j and pins[i] == pins[j]:
						done = False
						break
					j += 1
				if done:
					break
				k += 1
		i += 1
		same = False
	print(reslt)
	for i in range(n):
		j = 1
		pinseq = pins[i][0]
		while j < 4:
			pinseq += pins[i][j]
			j += 1
		print(pinseq)
		del pinseq


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(pins, n):
	counts = defaultdict(list)
	for pin in pins:
		counts[pin].append(pin)
	res = 0
	for (pin, dup) in counts.items():
		if len(dup) == 1:
			continue
		current_pins = dup[:]
		for i in range(1, len(current_pins)):
			unit = (int(current_pins[i - 1][-1]) + 1) % 10
			while current_pins[i][:-1] + str(unit) in pins:
				unit = (unit + 1) % 10
			current_pins[i] = current_pins[i][:-1] + str(unit)
			res += 1
		counts[pin] = current_pins
	write(res)
	for pin in pins:
		write(counts[pin].pop())

def main():
	for _ in range(r_int()):
		pins = []
		n = r_int()
		for _ in range(n):
			pins.append(input())
		solution(pins, n)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))

def main():
	t = iin()
	while t:
		t -= 1
		n = iin()
		ans = []
		dc = set()
		ch = 0
		todo = []
		for _ in range(n):
			s = input()
			if s in dc:
				ans.append(s)
				todo.append(_)
			else:
				ans.append(s)
				dc.add(s)
		for j in todo:
			s = ans[j]
			ch += 1
			for i in range(10):
				if str(i) + s[1:] not in dc:
					ans[j] = str(i) + s[1:]
					dc.add(ans[j])
					break
		print(ch)
		print(*ans, sep='\n')
main()


for _ in range(int(input())):
	n = int(input())
	p = []
	for line in range(n):
		p.append([int(i) for i in input()])
	replacement = 0
	for card_num in range(n):
		for ind in range(n):
			if card_num != ind and p[card_num] == p[ind]:
				not_accepted = set()
				for pin in p:
					not_accepted.add(pin[0])
				for candidate in range(10):
					if candidate not in not_accepted:
						p[card_num][0] = candidate
						replacement += 1
						break
	print(replacement)
	for pin in p:
		print(''.join((str(i) for i in pin)))


from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	count = 0
	l = []
	d = defaultdict(int)
	for i in range(n):
		s = input()
		l.append(s)
		d[s] += 1
	for i in range(len(l)):
		if d[l[i]] > 1:
			j = 0
			d[l[i]] -= 1
			count += 1
			while d[l[i]] != 0:
				temp = l[i]
				for k in range(0, 9):
					if j == 0:
						s1 = str(k) + temp[1] + temp[2] + temp[3]
					if j == 1:
						s1 = temp[0] + str(k) + temp[2] + temp[3]
					if j == 2:
						s1 = temp[0] + temp[1] + str(k) + temp[3]
					if j == 3:
						s1 = temp[0] + temp[1] + temp[2] + str(k)
					if d[s1] == 0:
						l[i] = s1
						break
				j += 1
			d[l[i]] += 1
	print(count)
	for i in l:
		print(i)


def check(arr, a):
	for i in range(len(arr)):
		if arr[i] == a:
			return True
	return False
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for j in range(n):
		pin = str(input())
		arr.append(pin)
	count = 0
	for j in range(n - 1):
		if check(arr[j + 1:], arr[j]):
			count += 1
			ini = arr[j][0]
			for k in range(10):
				temp = str(k) + arr[j][1:]
				if check(arr, temp):
					continue
				arr[j] = temp
				break
	print(count)
	for j in range(n):
		print(arr[j])


for _ in range(int(input())):
	n = int(input())
	codes = []
	zton = [False] * 10
	same = []
	moves = 0
	for k in range(n):
		codes.append(input())
	for i in range(0, len(codes)):
		zton[int(codes[i][0])] = True
		if i < len(codes) - 1:
			for j in range(i + 1, len(codes)):
				if codes[i] == codes[j]:
					same.append((codes[i], i))
					break
	for ccc in same:
		(cc, ind) = (ccc[0], ccc[1])
		for f in range(0, len(zton)):
			if zton[f] == False:
				cc = str(f) + cc[1:]
				zton[f] = True
				codes[ind] = cc
				moves += 1
				break
	print(moves)
	for gg in codes:
		print(gg)


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
t = intput()
for _ in range(t):
	n = intput()
	pins = []
	for i in range(n):
		pins.append(input().strip())
	sp = set(pins)
	pinscopy = pins[:]
	s = 0
	for k in sp:
		olo = pins.count(k)
		s += olo - 1
		if olo >= 2:
			tt = olo - 1
			for i in range(len(pins)):
				if not tt:
					break
				if pins[i] == k:
					for trial in range(10):
						newthing = list(pins[i])
						newthing[-1] = str(trial)
						newthing = ''.join(newthing)
						if newthing not in pinscopy:
							break
					pinscopy[i] = newthing
					tt -= 1
	print(s)
	for x in pinscopy:
		print(x)


def f(i, num, a):
	c = a[:]
	c[i] = str(num)
	return ''.join(c)
for i in range(int(input())):
	s = []
	sop = {0: set(), 1: set(), 2: set(), 3: set()}
	lol = set()
	popa = 0
	lo = {}
	for j in range(int(input())):
		b = input()
		a = list(b)
		lo[b] = lo.get(b, 0) + 1
		lol.add(b)
		s.append(a)
	s1 = []
	for a in s:
		flag = True
		if lo[''.join(a)] == 1:
			s1.append(''.join(a))
			continue
		lo[''.join(a)] -= 1
		for k in range(4):
			if flag:
				for l in range(10):
					if f(k, l, a) not in lol:
						popa += 1
						flag = False
						s1.append(f(k, l, a))
						lol.add(f(k, l, a))
						break
	print(popa)
	print('\n'.join(s1))


for i in range(0, int(input())):
	n = int(input())
	lista = []
	for i in range(0, n):
		lista.append(int(input()))
	seta = set(lista)
	largo = len(seta)

	def pin(x):
		if x > 999:
			return str(x)
		elif x > 99:
			return '0' + str(x)
		elif x > 9:
			return '00' + str(x)
		elif x > 0:
			return '000' + str(x)
		else:
			return '0000'
	if largo == n:
		print(0)
		for i in range(0, n):
			print(pin(lista[i]))
	else:
		print(n - largo)
		transitorio = []
		for i in range(0, n):
			if not lista[i] in transitorio:
				transitorio.append(lista[i])
				print(pin(lista[i]))
			else:
				resto = lista[i] % 10
				numero = lista[i] - resto
				j = 0
				while numero + j in transitorio or numero + j in lista:
					j += 1
				print(pin(numero + j))
				transitorio.append(numero + j)


for t in range(int(input())):
	n = int(input())
	p = [input() for i in range(n)]
	digits = [str(num) for num in range(10)]
	ans = 0
	for i in range(n):
		if p[i] in p[:i]:
			ans += 1
			for d in digits:
				if p[i][:3] + d not in p:
					p[i] = p[i][:3] + d
					break
	print(ans)
	for i in range(n):
		print(p[i])


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
for test in range(read_int()):
	n = read_int()
	cards = []
	for card in range(n):
		cards += [[int(c) for c in input().strip()]]
	count = 0
	for i in range(n):
		isdup = False
		while cards.count(cards[i]) > 1:
			isdup = True
			cards[i][0] = (cards[i][0] + 1) % 10
		if isdup:
			count += 1
	print(count)
	print('\n'.join((''.join((str(c) for c in card)) for card in cards)))


t = int(input())
while t:
	t -= 1
	n = int(input())
	f = []
	d = 0
	for i in range(n):
		f.append(input())
	for i in range(n):
		for j in range(n):
			if f[i] == f[j] and i != j:
				d += 1
				c = 0
				while True:
					f[j] = f[j][:3] + chr(48 + c)
					if f[j] not in f[:j] + f[j + 1:]:
						break
					else:
						c += 1
	print(d)
	for i in f:
		print(i)


from collections import defaultdict as dd
t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	d = dd(int)
	co = 0
	for i in range(n):
		arr += [[int(input()), i]]
		d[arr[-1][0]] += 1
	arr.sort()
	for i in range(n):
		if d[arr[i][0]] > 1:
			d[arr[i][0]] -= 1
			co += 1
			flg = 0
			while arr[i][0] in d:
				if arr[i][0] % 10 == 9:
					break
				arr[i][0] = arr[i][0] + 1
			while arr[i][0] in d:
				arr[i][0] = arr[i][0] - 1
			d[arr[i][0]] = 1
	print(co)
	l = [0] * n
	for i in range(n):
		l[arr[i][1]] = arr[i][0]
	for i in l:
		print((4 - len(str(i))) * '0' + str(i))


from collections import defaultdict
for _ in range(int(input())):
	arr = []
	n = int(input())
	for i in range(n):
		arr.append(input())
	d = {}
	e = defaultdict()
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			e[i] = i
			d[i] = 1
	cnt = n - len(d)
	ans = []
	for i in d:
		ans.append(i)
		if d[i] > 1:
			num = d[i] - 1
			for j in range(num):
				x = i[:3]
				ind = 0
				while ind <= 9:
					if x + str(ind) not in e:
						e[x + str(ind)] = i
						break
					else:
						ind += 1
	print(cnt)
	visited = {}
	for i in e:
		visited[i] = False
	for i in arr:
		f = 0
		for j in e:
			if e[j] == i and visited[j] == False:
				visited[j] = True
				print(j)
				f = 1
				break
			if f == 1:
				break


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		x = [input().strip() for _ in range(n)]
		s = set(x)
		print(n - len(s))
		r = set()
		r1 = []
		for i in x:
			if i not in r:
				r.add(i)
				r1.append(i)
			else:
				i = list(i)
				for num in range(10):
					i[-1] = str(num)
					i = ''.join(i)
					if i not in r and i not in s:
						break
					i = list(i)
				r.add(i)
				r1.append(i)
		for i in r1:
			print(i)
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')
main()


q = int(input())
for e in range(q):
	n_p = int(input())
	dic = {}
	new_pins = []
	equals = 0
	l = [int(input()) for t in range(n_p)]
	for pin in l:
		if pin not in dic.keys():
			dic[pin] = True
			new_pins.append(pin)
		else:
			equals += 1
			pin = pin // 10 * 10
			while pin in dic.keys() or pin in l:
				pin += 1
			dic[pin] = True
			new_pins.append(pin)
	print(equals)
	for y in new_pins:
		print('%04d' % y)


from collections import defaultdict, deque
for _ in range(int(input())):
	n = int(input())
	pins = [int(input()) for _ in range(n)]
	mpins = defaultdict(deque)
	for (i, pin) in enumerate(pins):
		mpins[pin].append(i)
	changes = 0
	for pin in pins:
		if len(mpins[pin]) > 1:
			new_pin = pin
			while new_pin in mpins:
				new_pin = (new_pin % 10 + 1) % 10 + pin // 10 * 10
			ind = mpins[pin].popleft()
			pins[ind] = new_pin
			mpins[new_pin].append(ind)
			changes += 1
	print(changes)
	for pin in pins:
		print(str(pin).zfill(4))


import sys
input = sys.stdin.readline
from collections import defaultdict
for T in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(list(input().strip()))
	count = 0
	for i in range(n):
		if arr[i] in arr[i + 1:]:
			count += 1
			j = 0
			k = 1
			while arr[i] in arr[i + 1:] or arr[i] in arr[:i]:
				arr[i][k] = str(j)
				if j == 9:
					k += 1
				j = (j + 1) % 10
	print(count)
	for i in range(n):
		print(''.join(arr[i]))


from collections import deque
from math import ceil, sqrt

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
t = ii()
while t:
	t -= 1
	m = {}
	n = ii()
	a = []
	for i in range(n):
		s = si()
		a.append(s)
		if s not in m:
			m[s] = 1
		else:
			m[s] += 1
	b = list(set(a))
	print(len(a) - len(b))
	b1 = []
	for i in range(n):
		s = a[i]
		if m[s] > 1:
			if s not in b1:
				b1.append(s)
			else:
				for j in num:
					x = s[:3] + j
					if x not in a:
						if x not in b1:
							b1.append(x)
							break
		else:
			b1.append(s)
	for i in b1:
		print(i)


import os
import sys
from io import BytesIO, IOBase
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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = [input() for _ in range(n)]
		res = 0
		for i in range(n):
			now = arr.count(arr[i])
			if now > 1:
				res += 1
				for j in range(10):
					s = str(j) + arr[i][1:]
					if s in arr:
						continue
					arr[i] = s
					break
		print(res)
		for i in arr:
			print(i)
main()


t = int(input())
while t:
	n = int(input())
	index = {}
	m = {}
	m1 = {}
	for i in range(n):
		l = input()
		if index.get(l, -1) == -1:
			index[l] = []
			index[l].append(i)
		else:
			index[l].append(i)
		m[l] = m.get(l, 0) + 1
		m1[l] = m1.get(l, 0) + 1
	cnt = 0
	for i in m:
		cnt += m[i] - 1
	print(cnt)
	ans = [0] * n
	for i in m:
		ans[index[i][0]] = i
		inc = 1
		m[i] -= 1
		while m[i]:
			i1 = str(i)
			for k in range(10):
				if int(i1[0]) != k:
					j = str(k) + i1[1:]
					if m1.get(j, -1) == -1:
						ans[index[i][inc]] = str(k) + i1[1:]
						inc += 1
						m1[str(k) + i1[1:]] = 1
						break
			m[i] -= 1
	for i in range(n):
		print(ans[i])
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	p = []
	for j in range(n):
		p.append(input())
	b = []
	cnt = 0
	for j in range(n):
		b.append(p[j][0])
	for j in range(n):
		for k in range(n):
			if j != k and p[j] == p[k]:
				for u in range(10):
					if str(u) not in b:
						p[k] = str(u) + p[k][1:]
						b.append(str(u))
						cnt += 1
						break
	print(cnt)
	for s in p:
		print(s)


for i in range(int(input())):
	n = int(input())
	p = []
	for j in range(n):
		p.append(input())
	cnt = n - len(set(p))
	print(cnt)
	for i in range(n):
		if p[i] in p[i + 1:]:
			j = 0
			while p[i] in p[i + 1:] + p[:i]:
				p[i] = p[i][:3] + str(j)
				j += 1
	for i in p:
		print(i)


t = int(input())
for i in range(t):
	dc = {}
	n = int(input())
	arr = []
	out = 0
	hm = {}
	arr2 = []
	for i in range(n):
		tem = input()
		arr2.append(tem)
		if tem in dc:
			dc[tem] += 1
			out += 1
		else:
			dc[tem] = 1
			arr.append(tem)
			hm[tem] = [tem]
	arr.sort()
	cur = 0
	for i in range(len(arr)):
		for j in range(dc[arr[i]] - 1):
			cur = '0'
			trun = arr[i][:3]
			while trun + cur in dc:
				cur = chr(ord(cur) + 1)
			dc[trun + cur] = 1
			hm[arr[i]].append(trun + cur)
	print(out)
	for i in range(len(arr2)):
		dc[arr2[i]] -= 1
		arr2[i] = hm[arr2[i]][dc[arr2[i]]]
		print(arr2[i])


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	ans1 = 0
	ans2 = [None] * n
	for j in range(n):
		if l[j] not in ans2:
			ans2[j] = l[j]
	for j in range(n):
		if ans2[j] == None:
			for pos in range(4):
				for d in range(9):
					jd = l[j][:pos] + chr(ord('0') + d) + l[j][pos + 1:]
					if jd not in ans2:
						ans1 += 1
						ans2[j] = jd
						break
				else:
					continue
				break
	print(ans1)
	for i in ans2:
		print(i)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	n = int(z())
	l = [z().strip() for _ in range(n)]
	p = n - len(set(l))
	print(p)
	for (i, pin) in enumerate(l):
		if l.count(pin) > 1:
			for j in range(10):
				t = str(j)
				tp = t + pin[1:]
				if l.count(tp) <= 0:
					l[i] = tp
					break
	for i in l:
		print(i)


for _ in range(int(input())):
	n = int(input())
	p = [input().strip() for _ in range(n)]
	ch = 0
	for (i, b) in enumerate(p):
		if p.count(b) > 1:
			for x in '0123456789':
				p[i] = x + b[1:]
				if p.count(p[i]) == 1:
					break
			ch += 1
	print(ch)
	for x in p:
		print(x)


t = int(input())
for tc in range(t):
	n = int(input())
	a = [int(input()) for i in range(n)]
	ans = 0
	for i in range(n):
		if a[i] in a[i + 1:]:
			a[i] += 1000
			a[i] %= 10000
			ans += 1
			while a[i] in a[:i] + a[i + 1:]:
				a[i] += 1000
				a[i] %= 10000
	print(ans)
	for i in a:
		print(str(i).zfill(4))


ls = int(input())
for l in range(ls):
	n = int(input())
	cf = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	b = []
	sc = 0
	c = set()
	p = [0 for i in range(n)]
	a = [[0 for i in range(4)] for j in range(n)]
	for i in range(n):
		a[i] = str(input())
		b = []
		b += a[i]
		if b[3] in cf:
			cf.remove(b[3])
	for i in range(0, n):
		b = []
		b += a[i]
		if a[i] in c:
			sc += 1
			b[3] = cf[0]
			p[i] = 1
			for k in range(4):
				p[i] = p[i] * 10 + int(b[k])
			cf.remove(b[3])
		else:
			c.add(a[i])
			p[i] = 1
			for k in range(4):
				p[i] = p[i] * 10 + int(b[k])
	print(sc)
	for i in range(n):
		t = p[i]
		for i in range(4):
			print(t // 10 ** (3 - i) % 10, end='')
		print()


efg = set()

def change(i, n):
	s = i[:3] + str((int(i[3]) + n) % 10)
	if s in efg:
		change(i, n + 1)
	else:
		efg.add(s)
		print(s)
t = int(input())
for i in range(t):
	n = int(input())
	d = dict()
	z = []
	efg = set()
	for j in range(n):
		s = input()
		z.append(s)
		efg.add(s)
		if s in d.keys():
			d[s] += 1
		else:
			d.update({s: 1})
	ans = 0
	d1 = []
	for i in d:
		ans += d[i] - 1
	print(ans)
	for i in z:
		if d[i] == 1:
			print(i)
			continue
		change(i, d[i] - 1)
		d[i] -= 1


def func(pos):
	global bala
	global val
	global cnt
	minn = int(4)
	cur = bala[pos]
	bala[pos] = '23245321'
	ans = ''
	for j in val:
		if j not in bala:
			if diff(str(cur), str(j)) < minn:
				ans = j
				minn = diff(str(cur), str(j))
	bala[pos] = ans
	cnt += minn

def diff(a, b):
	sol = int(0)
	a = list(a)
	b = list(b)
	if a[0] != b[0]:
		sol += 1
	if a[1] != b[1]:
		sol += 1
	if a[2] != b[2]:
		sol += 1
	if a[3] != b[3]:
		sol += 1
	return sol
val = []
n = int(0)
for i in range(10):
	for j in range(10):
		for k in range(10):
			for l in range(10):
				val.append(str(i) + str(j) + str(k) + str(l))
				n += 1
for i in range(int(input())):
	bala = []
	cnt = int(0)
	for j in range(int(input())):
		bala.append(input())
	for j in range(len(bala)):
		if bala[j] in bala[j + 1:]:
			func(j)
	print(cnt)
	for j in range(len(bala)):
		print(bala[j])


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = [list(input()) for _ in range(n)]
	s = set()
	ss = set()
	for x in a:
		ss.add(tuple(x))
	ans = 0
	res = []
	for (i, x) in enumerate(a):
		if not tuple(x) in s:
			res.append(x)
			s.add(tuple(x))
			continue
		ans += 1
		for j in range(10):
			now = x[:]
			now[0] = str(j)
			if tuple(now) in s or now == x or tuple(now) in ss:
				continue
			res.append(now)
			s.add(tuple(now))
			break
	print(ans)
	for x in res:
		print(''.join(x))


from random import randint
n = int(input())
for x in range(n):
	wyn = 0
	t = []
	m = int(input())
	for y in range(m):
		t.append([str(input()), y])
	t = sorted(t, key=lambda x: (x[0], x[1]), reverse=True)
	t_pom = []
	for z in range(len(t) - 1):
		t_pom.append(t[z][0])
		if t[z][0] == t[z + 1][0]:
			wyn += 1
			tmp_tab = [y for y in t[z][0]]
			while True:
				poz = randint(0, 3)
				nowa_cyfra = randint(0, 9)
				tmp_tab_2 = [y for y in t[z][0]]
				tmp_tab_2[poz] = str(nowa_cyfra)
				tmp_str = ''.join(tmp_tab_2)
				if tmp_str in t_pom:
					continue
				else:
					t[z][0] = tmp_str
					t_pom.append(tmp_str)
					break
	t = sorted(t, key=lambda x: (x[1], x[0]))
	print(wyn)
	for xx in t:
		print(xx[0])


import os, sys

def solve(pins):
	new_pins = [None] * len(pins)
	used_pins = set()
	changed_digits = 0
	for x in range(len(pins)):
		if pins.count(pins[x]) == 1:
			new_pins[x] = pins[x]
			used_pins.add(pins[x])
	for x in range(len(pins)):
		if new_pins[x] is None:
			old_pin = pins[x]
			if old_pin not in used_pins:
				used_pins.add(old_pin)
				new_pins[x] = old_pin
			else:
				removed_last_digit_pin = old_pin // 10 * 10
				for addition in range(0, 10):
					new_pin = removed_last_digit_pin + addition
					if new_pin not in used_pins:
						used_pins.add(new_pin)
						new_pins[x] = new_pin
						changed_digits += 1
						break
	return (changed_digits, [str(q).zfill(4) for q in new_pins])
num = int(input().strip())
for x in range(num):
	n = int(input().strip())
	pins = [int(input().strip()) for _ in range(n)]
	(k, new_pins) = solve(pins)
	print(k)
	for p in new_pins:
		print(p)


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		t = [int(input()) for k in range(n)]
		c = 0
		for i in range(n):
			if t.count(t[i]) >= 2:
				c += 1
				d = t[i] % 10
				f = 0
				for k in range(10):
					if k != d and 10 * (t[i] // 10) + k not in t:
						t[i] = 10 * (t[i] // 10) + k
						break
		print(c)
		for e in t:
			print(str(e).zfill(4))
main()


import math
import bisect
from collections import defaultdict
from collections import OrderedDict
from itertools import combinations
import heapq
from collections import deque
for _ in range(int(input())):
	n = int(input())
	chk = [0] * n
	c = 0
	ar = []
	for i in range(n):
		x = list(map(int, input()))
		ar.append(x)
	f = 0
	z = []
	for i in range(n):
		p = ''
		for j in range(4):
			y = ar[i][j]
			p += str(y)
		z.append(int(p))
	l = n - len(list(set(z)))
	print(l)
	for j in range(n):
		for i in range(n):
			if j != i and ar[i] == ar[j]:
				f = 0
				t = ar[j][:]
				for k in range(10):
					t[0] = k
					if t not in ar:
						ar[j] = t
						f = 1
						break
				if f == 0:
					t = ar[j][:]
					for k in range(10):
						t[1] = k
						if t not in ar:
							ar[j] = t
							f = 1
							break
				if f == 0:
					t = ar[j][:]
					for k in range(10):
						t[2] = k
						if t not in ar:
							ar[j] = t
							f = 1
							break
				if f == 0:
					t = ar[j][:]
					for k in range(10):
						t[3] = k
						if t not in ar:
							ar[j] = t
							f = 1
							break
				if f == 1:
					break
	for i in range(n):
		for j in range(4):
			print(ar[i][j], end='')
		print()


t = int(input())
for w in range(t):
	n = int(input())
	l = [input() for x in range(n)]
	ct = 0
	for i in range(n):
		if l.count(l[i]) > 1:
			for j in range(10):
				if l[i][:3] + str(j) not in l:
					l[i] = l[i][:3] + str(j)
					break
			ct += 1
	print(ct)
	for i in l:
		print(i)


t = int(input())
for i in range(t):
	n = int(input())
	cards = list()
	cou = 0
	for j in range(n):
		cards.append(input())
	br = False
	for j in range(n):
		br = False
		if cards.count(cards[j]) > 1:
			for k in range(4):
				for m in range(10):
					temp = list(cards[j])
					temp[k] = str(m)
					temp = ''.join(temp)
					if temp not in cards:
						cards[j] = temp
						cou += 1
						br = True
						break
				if br:
					break
	print(cou)
	print(*cards, sep='\n')


from collections import Counter as co
for ___ in range(int(input().strip())):
	n = int(input().strip())
	arr = []
	for _ in range(n):
		arr.append(input().strip())
	c = co(arr)
	if max(c.keys()) == 1:
		print(0)
		for x in arr:
			print(arr)
	else:
		ans = 0
		nr = []
		ava = [set([num for num in range(10)]) for t in range(4)]
		for i in range(n):
			for j in range(4):
				if int(arr[i][j]) in ava[j]:
					ava[j].remove(int(arr[i][j]))
		for x in arr:
			if c[x] == 1:
				nr.append(x)
			else:
				c[x] -= 1
				ans += 1
				xx = [int(pp) for pp in list(x)]
				for i in range(len(ava)):
					if len(ava[i]) > 0:
						xx[i] = ava[i].pop()
						break
				new = ''.join([str(N) for N in xx])
				nr.append(new)
		print(ans)
		for x in nr:
			print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	p = []
	for i in range(n):
		p.append(input())
	sp = sorted(p)
	pp = list(set(p))
	k = n - len(pp)
	print(k)
	b = [0]
	for i in range(n - 1):
		if sp[i] != sp[i + 1]:
			b.append(i + 1)
	b.append(n)
	digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(len(b) - 1):
		temp = b[i + 1] - b[i] - 1
		if temp == 0:
			continue
		candidate = []
		oldpin = sp[b[i]]
		for digit in digits:
			newpin = oldpin[:3] + digit
			if newpin not in pp:
				candidate.append(newpin)
				pp.append(newpin)
			if len(candidate) == temp:
				break
		for j in range(b[i] + 1, b[i + 1]):
			sp[j] = candidate[j - b[i] - 1]
	for i in range(len(b) - 1):
		pin = sp[b[i]]
		k = b[i] + 1
		flag = False
		for j in range(n):
			if not flag and p[j] == pin:
				flag = True
				continue
			if p[j] == pin:
				p[j] = sp[k]
				k += 1
	for i in range(len(p)):
		print(p[i])


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	a = int(input())
	mas = []
	ans = 0
	jk = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	for i in range(a):
		s = input()
		mas.append(s)
	for i in range(a):
		if mas[i] in mas[:i] or mas[i] in mas[i + 1:]:
			for j in jk:
				if str(j) + mas[i][1:] in mas[:i] or str(j) + mas[i][1:] in mas[i + 1:]:
					continue
				else:
					mas[i] = str(j) + mas[i][1:]
					ans += 1
					break
	print(ans)
	for row in mas:
		print(row)


from sys import *
from math import *
for _ in range(int(input())):
	n = int(input())
	lis = []
	for i in range(n):
		x = int(input())
		lis.append(x)
	ans = 0
	for i in range(n - 1):
		if lis[i] in lis[i + 1:]:
			ans += 1
			while lis[i] in lis[:i] + lis[i + 1:]:
				lis[i] += 1000
				lis[i] %= 10000
	print(ans)
	f = []
	for i in range(len(lis)):
		if lis[i] != 0:
			d = int(log10(lis[i]))
			x = 4 - d
		else:
			x = 4
		a = []
		for j in range(x - 1):
			a.append(0)
		a.append(lis[i])
		f.append(a)
	for i in range(len(f)):
		print(*f[i], sep='')


import os
import sys
from io import BytesIO, IOBase
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')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	pins = []
	repeats = {}
	for s in range(n):
		pin = input()
		pins.append(pin)
		if not pin in repeats:
			repeats[pin] = [s]
		else:
			repeats[pin].append(s)
	available = list(range(10))
	for b in range(n):
		if int(pins[b][0]) in available:
			available.remove(int(pins[b][0]))
	minval = 0
	for s in repeats.keys():
		if len(repeats[s]) > 1:
			minval += len(repeats[s]) - 1
			for b in range(len(repeats[s]) - 1):
				ind1 = repeats[s][b]
				string1 = pins[ind1]
				outy = ''
				outy += str(available.pop())
				for k in range(1, 4):
					outy += string1[k]
				pins[ind1] = outy
	print(minval)
	for s in range(n):
		print(pins[s])


a = int(input())
for i in range(a):
	n = int(input())
	l = []
	ls = []
	for i in range(n):
		k = input()
		l.append(k)
		ls.append(k)
	d = list(set(l))
	a = [[0 for i in range(11)] for j in range(5)]
	for i in range(len(d)):
		for j in range(4):
			a[j][int(d[i][j])] = 1
	f = set()
	ans = 0
	ansl = []
	for i in l:
		if i in f:
			r = 0
			ik = 0
			for j in range(10):
				if a[0][j] == 0:
					a[0][j] = 1
					r = 1
					ik = j
					break
			ansl.append(str(ik) + i[1:])
			ans += 1
			if r == 0:
				r = 0
				ik = 0
				for j in range(10):
					if a[1][j] == 0:
						a[1][j] = 1
						r = 1
						ik = j
						break
				ansl.append(i[0] + str(ik) + i[2:])
				ans += 1
				if r == 0:
					r = 0
					ik = 0
					for j in range(10):
						if a[2][j] == 0:
							a[2][j] = 1
							r = 1
							ik = j
							break
					ansl.append(i[0:2] + str(ik) + i[3:])
					ans += 1
					if r == 0:
						r = 0
						ik = 0
						for j in range(10):
							if a[3][j] == 0:
								a[3][j] = 1
								r = 1
								ik = j
								break
						ansl.append(i[0:-1] + str(ik))
						ans += 1
		else:
			f.add(i)
			ansl.append(i)
	print(ans)
	for i in ansl:
		print(i)


for _ in range(int(input())):
	n = int(input())
	cards = []
	tmp = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(n):
		cards.append(input())
		if cards[-1][-1] in tmp:
			tmp.remove(cards[-1][-1])
	ans = []
	cnt = 0
	for code in cards:
		if code not in ans:
			ans.append(code)
		else:
			cnt += 1
			a = list(code)
			a[-1] = tmp.pop(0)
			ans.append(''.join(a))
	print(cnt)
	for code in ans:
		print(code)


for _ in range(int(input())):
	n = int(input())
	pins = []
	d1 = []
	ans = 0
	for i in range(n):
		pins.append(list(input()))
		d1.append(pins[-1][0])
	for i in range(len(pins)):
		for j in range(i + 1, len(pins)):
			if pins[i] == pins[j]:
				for k in '1234567890':
					if k not in d1:
						pins[j][0] = k
						d1.append(k)
						ans += 1
						break
	print(ans)
	for i in pins:
		print(''.join(i))


for __ in range(int(input())):
	n = int(input())
	l = []
	h = [0] * 10
	for i in range(n):
		no = input()
		l.append(no)
		h[ord(no[0]) - ord('0')] = 1
	count = 0
	for i in range(n):
		for j in range(i + 1, n):
			if l[i] == l[j]:
				for k in range(10):
					if h[k] == 0:
						l[i] = str(k) + l[i][1:]
						h[k] = 1
						count += 1
						break
	print(count)
	for i in range(n):
		print(l[i])


def main():
	n = int(input())
	d = []
	s = set()
	for i in range(n):
		k = input()
		d.append(k)
		s.add(k[3])
	t = 0
	z = 0
	ans = []
	for i in range(n):
		T = True
		for j in range(n):
			if j > i:
				if d[i] == d[j] and T:
					while str(t) in s:
						t += 1
					d[i] = d[i][:3] + str(t)
					ans.append(d[i])
					T = False
					z += 1
					s.add(str(t))
		if T:
			z += 0
			ans.append(d[i])
	print(z)
	for i in ans:
		print(i)
a = int(input())
for i in range(a):
	main()


t = int(input())
for tc in range(t):
	n = int(input())
	p = []
	for i in range(n):
		pin = input()
		p.append(pin)
	li = [x for x in range(10)]
	s = set(li)
	d = {}
	for i in range(10):
		d[i] = []
	for i in range(n):
		d[int(p[i][3])].append(i)
		s.discard(int(p[i][3]))
	count = 0
	for i in range(n):
		for j in range(0, i):
			if p[i] == p[j]:
				p[j] = p[j][:3] + str(s.pop())
				count += 1
	print(count)
	for i in range(n):
		print(p[i])


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		c = input()
		a.append(c)
	count = 0
	for i in range(n):
		if a[i] in a[i + 1:]:
			count += 1
			j = 48
			while a[i] in a[i + 1:] + a[:i]:
				a[i] = a[i][:3] + chr(j)
				j += 1
	print(count)
	for i in a:
		print(i)


t = int(input())
for i in range(t):
	n = int(input())
	data = []
	for i in range(n):
		data.append(input())
	dic = {}
	lst = [0 for i in range(10)]
	for i in range(n):
		lst[int(data[i][0])] += 1
	k = 0
	count = 0
	for i in range(n):
		if data[i] in dic:
			j = k
			while j < 10:
				if lst[j] == 0:
					data[i] = str(j) + data[i][1:]
					k = j + 1
					count += 1
					break
				else:
					j += 1
		else:
			dic[data[i]] = 1
	print(count)
	for i in range(n):
		print(data[i])


for _ in range(int(input())):
	n = int(input())
	d = {}
	a = []
	for i in range(n):
		pin = int(input())
		a.append(pin)
		d[pin] = d.get(pin, 0) + 1
	print(sum(d.values()) - len(d.values()))
	dn = {}
	for i in a:
		if dn.get(i, 0) == 0:
			print((4 - len(str(i))) * '0' + str(i))
			dn[i] = 1
		else:
			ne = i // 10 * 10
			while ne in dn or ne in d:
				ne += 1
			print((4 - len(str(ne))) * '0' + str(ne))
			dn[ne] = 1


for _ in range(int(input())):
	n = int(input())
	p = {}
	hehe = [0 for i in range(n)]
	ch = []
	ch_i = []
	for i in range(n):
		x = str(input())
		if x in p:
			ch.append(x)
			ch_i.append(i)
		else:
			p[x] = 1
			hehe[i] = x
	change = 0
	it = 0
	ind = 0
	for i in ch:
		x = str(i)
		for j in range(1, 10):
			alpha = str(j) + x[1:]
			beta = x[:1] + str(j) + x[2:]
			gamma = x[:2] + str(j) + x[3:]
			theta = x[:3] + str(j)
			if alpha not in p:
				p[alpha] = 1
				hehe[ch_i[ind]] = alpha
				break
			elif beta not in p:
				p[beta] = 1
				hehe[ch_i[ind]] = beta
				break
			elif gamma not in p:
				p[gamma] = 1
				hehe[ch_i[ind]] = gamma
				break
			elif theta not in p:
				p[theta] = 1
				hehe[ch_i[ind]] = theta
				break
		ind += 1
	print(len(ch))
	for i in hehe:
		print(i)


for _ in range(int(input())):
	n = int(input())
	total_pin = [input() for x in range(n)]
	pins = []
	changes = 0
	for pin in total_pin:
		if pin not in pins:
			pins.append(pin)
			continue
		changes += 1
		for i in '0123456789':
			pin = i + pin[1:]
			if pin not in pins and pin not in total_pin:
				pins.append(pin)
				break
	print(changes)
	for i in pins:
		print(i)


import sys

def print(q):
	sys.stdout.write(q + '\n')

def main():

	def pro(i, num, a):
		z = a[:]
		z[i] = str(num)
		x = ''
		for i in range(4):
			x += z[i]
		return x
	t = int(sys.stdin.readline().strip())
	for qwertyuiop in range(t):
		(q, sett, delta, w, res) = ([], set(), 0, {}, [])
		for i in range(int(sys.stdin.readline().strip())):
			b = sys.stdin.readline().strip()
			a = list(b)
			w[b] = w.get(b, 0) + 1
			sett.add(b)
			q.append(a)
		for i in q:
			fl = True
			if w[''.join(i)] == 1:
				res.append(''.join(i))
				continue
			w[''.join(i)] -= 1
			for o in range(4):
				if fl:
					for l in range(10):
						if pro(o, l, i) not in sett:
							delta += 1
							fl = False
							res.append(pro(o, l, i))
							sett.add(pro(o, l, i))
							break
		print(str(delta))
		for i in res:
			print(i)
main()


n = int(input())
for i in range(n):
	m = int(input())
	l = []
	units = [0] * 10
	changes_num = 0
	for i in range(m):
		s = str(input())
		units[int(s[-1])] = 1
		l.append(s)
	for i in range(m):
		s = l[i]
		if l.count(s) > 1:
			c = units.index(0)
			s = s[:-1] + str(c)
			units[c] = 1
			changes_num += 1
		l[i] = s
	print(changes_num)
	for el in l:
		print(el)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	ar = set(arr)
	print(n - len(ar))
	new_arr = []
	for i in arr:
		if i not in new_arr:
			new_arr.append(i)
		else:
			for j in range(10):
				val = str(j) + i[1:]
				if val not in ar:
					ar.add(val)
					new_arr.append(val)
					break
	print('\n'.join(new_arr))


for _ in range(int(input())):
	n = int(input())
	q = [list(input()) for _ in range(n)]
	ans = [0]
	for pin in q:
		t = 0
		for i in range(10):
			if q.count(pin) == 1:
				break
			pin[-1] = str(i)
			t = 1
		ans[0] += t
		ans.append(''.join(map(str, pin)))
	print('\n'.join(map(str, ans)))


for a0 in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append([list(input()), i])
	l = sorted(l, key=lambda l: l[0])
	c = 0
	for i in range(n - 1):
		j = i
		while j < n - 1 and l[j][0] == l[j + 1][0]:
			j += 1
		c += j - i
		for k in range(i, j):
			l[k][0][k % 4] = str((int(l[k][0][k % 4]) + 5 + k) % 10)
			if k < n - 1 and l[k][0] == l[k + 1][0]:
				l[k][0][k % 4] = str((int(l[k][0][k % 4]) + 7 + k) % 10)
	s = [0] * n
	for i in range(n):
		s[l[i][1]] = ''.join(l[i][0])
	print(c)
	print(*s, sep='\n')


n = int(input())
for i in range(0, n):
	o = int(input())
	L = []
	Q = [0] * 10000
	W = []
	for j in range(0, o):
		s = input().rstrip()
		L.append(s)
		W.append(s)
		Q[int(s)] += 1
	if len(list(set(L))) == o:
		print(0)
		for j in range(0, len(L)):
			print(L[j])
	else:
		ans = 0
		for j in range(0, len(Q)):
			if Q[j] != 0:
				ans += Q[j]
				ans -= 1
		print(ans)
		F = []
		for j in range(0, len(L)):
			A = int(L[j])
			if Q[A] <= 1:
				F.append(L[j])
				continue
			else:
				Q[A] -= 1
				C = list(L[j])
				for k in range(0, len(C)):
					G = 0
					for M in range(1, 9):
						E = list(L[j])
						E[k] = str(M)
						H = ''.join(E)
						if H not in W:
							W.append(H)
							F.append(H)
							G = 1
							break
					if G == 1:
						break
		for j in range(0, len(F)):
			print(F[j])


t = int(input())
for test in range(t):
	n = int(input())
	arr = []
	flag = [False for i in range(10)]
	for i in range(n):
		s = input()
		flag[int(str(s)[3])] = True
		arr.append(s)
	ans = 0
	s = []
	for i in range(n):
		if arr[i] in s:
			ans += 1
			temp = int(str(arr[i])[3])
			for j in range(0, 10):
				if flag[j] == False and j != temp:
					flag[j] = True
					arr[i] = arr[i][0:3] + str(j)
					s.append(arr[i])
					break
		s.append(arr[i])
	print(ans)
	for i in range(n):
		x = len(str(arr[i]))
		res = '0' * (4 - x) + str(arr[i])
		print(res)


for _ in range(int(input())):
	n = int(input())
	d = {}
	l = []
	for i in range(n):
		a = input()
		l.append(a)
		if a in d.keys():
			d[a] += 1
		else:
			d.setdefault(a, 1)
	ans = 0
	d1 = d.copy()
	final_ans = []
	for i in range(n - 1, -1, -1):
		j = d[l[i]]
		if j == 1:
			final_ans.append(l[i])
		else:
			ans += 1
			d[l[i]] -= 1
			for z in range(4):
				f = 0
				for y in range(10):
					temp = l[i][:z] + str(y) + l[i][z + 1:]
					if temp not in d1.keys():
						d1.setdefault(temp, 1)
						final_ans.append(temp)
						f = 1
						break
				if f == 1:
					break
	print(ans)
	for i in final_ans[::-1]:
		print(i)


import math
t = int(input())
for i in range(t):
	n = int(input())
	b = []
	a = []
	for j in range(n):
		f = input()
		b.append(f)
		a.append(int(f[0]))
	s = 0
	for j in range(n):
		p = b.count(b[j])
		if p > 1:
			s += 1
			for p in range(10):
				if p not in a:
					b[j] = str(p) + b[j][1:]
					a.append(p)
					break
	print(s)
	for j in b:
		print(j)


from collections import Counter
for step in range(int(input())):
	Array = []
	for num in range(int(input())):
		x = input()
		Array.append(x)
	di = dict(Counter(Array))
	sum1 = 0
	Ans = ''
	for i in range(len(Array) - 1):
		if di[Array[i]] != 1:
			y = Array[i]
			di[y] -= 1
			z = list(Array[i])
			while y in di:
				z[0] = str((int(z[0]) + 1) % 10)
				y = ''.join(z)
			di[y] = 1
			Ans += y + '\n'
			sum1 += 1
		else:
			Ans += Array[i] + '\n'
	i = len(Array) - 1
	Ans += Array[i]
	print(str(sum1) + '\n' + Ans)


mod = 10 ** 9 + 7
INF = float('inf')

def readInts():
	return list(map(int, input().split()))

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

def I():
	return int(input())
q = I()
from collections import Counter, defaultdict
for _ in range(q):
	n = I()
	S = [input() for _ in range(n)]
	dic = Counter(S)
	ans = 0
	next = defaultdict(int)
	for (k, v) in dic.items():
		next[k] = int(v)
		ans += v - 1
	print(ans)
	RES = defaultdict(int)
	for idx in range(n):
		value = int(S[idx])
		if RES[value] == 0:
			print('%04d' % value)
			RES[value] = 1
			dic[value] -= 1
			next[value] = value
		elif dic[S[idx]] >= 1:
			raw_number = next[value]
			for i in range(1, 3):
				dived = raw_number // 10 ** i
				MOD = dived % 10
				raw_number -= 10 ** i * MOD
				for j in range(10):
					raw_number += (MOD + j + 1) % 10 * max(1, 10 ** i)
					if RES[raw_number] == 0 and dic[str(raw_number)] == 0:
						print('%04d' % raw_number)
						RES[raw_number] = 1
						next[value] = raw_number
						dic[S[idx]] -= 1
						break
					raw_number -= (MOD + j + 1) % 10 * max(1, 10 ** i)
				else:
					continue
				break


t = int(input())
for it in range(t):
	n = int(input())
	d = {}
	arr = []
	for i in range(n):
		s = input().strip()
		arr.append(s)
	ans = 0
	for i1 in range(n):
		cc = 0
		for i in range(n):
			if arr[i1] == arr[i]:
				cc += 1
		if cc == 1:
			continue
		ss = arr[i1]
		temp = []
		for i in ss:
			temp.append(i)
		flag = False
		for i in range(len(temp)):
			for j in range(10):
				lol = temp[i]
				temp[i] = str(j)
				xx = ''.join(temp)
				cc = 0
				for k in range(n):
					if xx == arr[k]:
						cc += 1
				if cc == 0:
					flag = True
					break
				else:
					temp[i] = lol
			if flag:
				break
		ans += 1
		arr[i1] = ''.join(temp)
	print(ans)
	for i in arr:
		print(i)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	Ss = [input().rstrip() for _ in range(N)]
	Query.append((N, Ss))
for (N, Ss) in Query:
	mustchange = [False] * N
	already = set()
	c = 0
	for (i, S) in enumerate(Ss):
		if S in already:
			c += 1
			mustchange[i] = True
		else:
			already.add(S)
	ans = []
	for (i, S) in enumerate(Ss):
		if mustchange[i]:
			for n in range(10):
				T = str(n) + S[1:]
				if not T in already:
					ans.append(T)
					already.add(T)
					break
				R = S[:3] + str(n)
				if not R in already:
					ans.append(R)
					already.add(R)
					break
		else:
			ans.append(S)
	print(c)
	print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	arr = []
	for __ in range(n):
		arr.append(input())
	s = set(arr)
	print(n - len(s))
	new_s = []
	for i in arr:
		if i not in new_s:
			new_s.append(i)
		else:
			for j in range(10):
				x = str(j) + i[1:]
				if x not in s:
					s.add(x)
					new_s.append(x)
					break
	print('\n'.join(new_s))


t = int(input())
for _ in range(t):
	n = int(input())
	codes = []
	for _ in range(n):
		codes.append(input().strip())
	rs = [[0 for _ in range(10)] for _ in range(4)]
	for code in codes:
		for i in range(4):
			rs[i][int(code[i])] += 1
	g = []
	for (i, z) in enumerate(rs):
		cnt = 0
		for l in z:
			cnt += max(0, l - 1)
		g.append((i, cnt))
	(mi, fds) = min(g, key=lambda z: z[1])
	used = []
	cnt = 0
	gr = set((i for (i, x) in enumerate(rs[mi]) if x == 0))
	for c in codes:
		if c not in used:
			used.append(c)
			continue
		used.append(c[:mi] + str(gr.pop()) + c[mi + 1:])
		cnt += 1
	print(cnt)
	print('\n'.join(used))


import sys
readline = sys.stdin.readline
mr = lambda : map(int, readline().split())
t = int(readline())
Ans = []
for _ in range(t):
	n = int(readline())
	tmp = [str(readline())[:4] for _ in range(n)]
	d = dict()
	for i in range(n):
		d[tmp[i]] = d.get(tmp[i], [])
		d[tmp[i]].append(i)
	Ans.append(n - len(d))
	mySet = set([j for j in range(10)]).difference(set([int(s[0]) for s in tmp]))
	newArr = [''] * n
	for x in d:
		nn = len(d[x])
		newArr[d[x][0]] = x
		for j in range(1, nn):
			newArr[d[x][j]] = str(mySet.pop()) + tmp[d[x][j]][1:]
	for x in newArr:
		Ans.append(x)
print('\n'.join(map(str, Ans)))


t = int(input())
while t:
	n = int(input())
	A = []
	for i in range(n):
		p = input()
		A.append(p)
	b = []
	count = 0
	for i in range(n):
		if A[i] in b:
			a = A[i]
			if a[0] + a[1] + a[2] + str((int(a[3]) + 1) % 10) not in A + b:
				b.append(a[0] + a[1] + a[2] + str((int(a[3]) + 1) % 10))
				count += 1
			elif a[0] + a[1] + str((int(a[2]) + 1) % 10) + a[3] not in A + b:
				b.append(a[0] + a[1] + str((int(a[2]) + 1) % 10) + a[3])
				count += 1
			elif a[0] + str((int(a[1]) + 1) % 10) + a[2] + a[3] not in A + b:
				b.append(a[0] + str((int(a[1]) + 1) % 10) + a[2] + a[3])
				count += 1
			elif str((int(a[0]) + 1) % 10) + a[1] + a[2] + a[3] not in A + b:
				b.append(str((int(a[0]) + 1) % 10) + a[1] + a[2] + a[3])
				count += 1
			elif a[0] + a[1] + a[2] + str((int(a[3]) + 2) % 10) not in A + b:
				b.append(a[0] + a[1] + a[2] + str((int(a[3]) + 2) % 10))
				count += 1
			elif a[0] + a[1] + str((int(a[2]) + 2) % 10) + a[3] not in A + b:
				b.append(a[0] + a[1] + str((int(a[2]) + 2) % 10) + a[3])
				count += 1
			elif a[0] + str((int(a[1]) + 2) % 10) + a[2] + a[3] not in A + b:
				b.append(a[0] + str((int(a[1]) + 2) % 10) + a[2] + a[3])
				count += 1
			elif str((int(a[0]) + 2) % 10) + a[1] + a[2] + a[3] not in A + b:
				b.append(str((int(a[0]) + 2) % 10) + a[1] + a[2] + a[3])
				count += 1
			elif a[0] + a[1] + a[2] + str((int(a[3]) + 3) % 10) not in A + b:
				b.append(a[0] + a[1] + a[2] + str((int(a[3]) + 3) % 10))
				count += 1
			elif a[0] + a[1] + str((int(a[2]) + 3) % 10) + a[3] not in A + b:
				b.append(a[0] + a[1] + str((int(a[2]) + 3) % 10) + a[3])
				count += 1
		else:
			b.append(A[i])
	print(count)
	for i in range(n):
		print(b[i])
	t -= 1


for i in range(int(input())):
	(n, chng) = (int(input()), 0)
	a = []
	for j in range(n):
		a.append(list(input()))
	for j in range(n):
		(flg, tmp, num) = (1, 0, a[j][3])
		while flg:
			for k in range(n):
				if j != k and a[j] == a[k]:
					a[j][3] = str(tmp)
					flg = 0
					break
			if a.count(a[j]) == 1 and flg:
				flg = 0
			elif a.count(a[j]) == 1 and (not flg):
				chng += 1
			else:
				(flg, tmp) = (1, tmp + 1)
				a[j][3] = num
	print(chng)
	for j in range(n):
		print(''.join(a[j]))


for _ in range(int(input())):
	n = int(input())
	k = 0
	d = []
	d = set(d)
	c = 0
	ar = []
	for i in range(n):
		s = input()
		ar.append(s)
	another = set(ar)
	ans = []
	for s in ar:
		if s not in d:
			d.add(s)
			ans.append(s)
		else:
			f = 0
			c += 1
			for j in range(4):
				temp1 = s[:j]
				temp2 = s[j + 1:]
				for i in range(10):
					string = temp1 + str(i) + temp2
					if string not in d and string not in another:
						d.add(string)
						ans.append(string)
						f = 1
						break
				if f == 1:
					break
	print(c)
	for i in ans:
		print(i)


def change(inputList, pused):
	reslst = []
	chgcnt = 0
	hs = set()
	for s in inputList:
		lstr = s
		if hs.__contains__(s):
			chgcnt += 1
			for (index, elem) in enumerate(pused):
				if not elem:
					pused[index] = True
					lstr = str(index) + lstr[1:]
					break
		hs.add(lstr)
		reslst.append(lstr)
	reslst.insert(0, chgcnt)
	return reslst
t = int(input().rstrip())
for x in range(t):
	n = int(input().rstrip())
	inputList = []
	used = [False] * 10
	for y in range(n):
		p = input().rstrip()
		used[int(p[0])] = True
		inputList.append(p)
	reslist = change(inputList, used)
	for res in reslist:
		print(str(res))


for _ in range(int(input())):
	n = int(input())
	arr = []
	num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	stuff = {}
	repeat1 = []
	for i in range(n):
		arr.append(input())
		stuff[i] = arr[-1]
	s = []
	repeat = []
	for i in range(n):
		if arr[i] not in s:
			s.append(arr[i])
		else:
			repeat.append(arr[i])
			repeat1.append([arr[i], i])
	ans = 0
	l = 0
	for x in repeat:
		point = repeat1[l][1]
		l += 1
		f = True
		x = list(x)
		for j in range(4):
			for k in range(10):
				q = ''
				m = x[j]
				x[j] = num[k]
				if q.join(x) not in s:
					s.append(q.join(x))
					f = False
					ans += 1
					stuff[point] = q.join(x)
					break
				else:
					x[j] = m
			if f == False:
				break
	print(ans)
	for it in stuff:
		print(stuff[it])


t = int(input())
for j in range(t):
	k = int(input())
	a = []
	for q in range(k):
		u = int(input())
		a.append(u)
	b = [-1 for i in range(k)]
	ishkal = []
	bor = {i for i in range(10)}
	ans = 0
	for o in range(k):
		q = a[o]
		if q in b:
			ishkal.append(q)
			ans += 1
		else:
			b[o] = q
	for q in ishkal:
		while 1:
			son = q
			x = bor.pop()
			son //= 10
			son = son * 10 + x
			if son not in b:
				break
		for look in range(k):
			ss = b[look]
			if ss == -1:
				b[look] = son
				break
	print(ans)
	for i in b:
		h = 4 - len(str(i))
		for w in range(h):
			print(0, end='')
		print(i)


exec('\nfor _ in range(int(input())):\n    n=int(input());arr={};num=[\'0\',\'1\',\'2\',\'3\',\'4\',\'5\',\'6\',\'7\',\'8\',\'9\'];s=set();repeat=[];ans=0\n    for i in range(n):\n        arr[i]=input()\n        if arr[i] in s:repeat.append([arr[i],i])\n        else:s.add(arr[i])\n    for x in repeat:\n        point=x[1];f=True;p=list(x[0])\n        for j in range(4):\n            for k in range(10):\n                q="";m=p[j];p[j]=num[k];t=q.join(p)\n                if t not in s:s.add(t);f=False;ans+=1;arr[point]=t;break\n                else:p[j]=m\n            if not f:break\n    print(ans)\n    for it in arr:print(arr[it])\n')


for _ in range(int(input())):
	n = int(input())
	l = [int(input()) for x in range(n)]
	same = 0
	for i in range(n):
		if l[i] in l[i + 1:]:
			same += 1
			while l[i] in l[i + 1:] + l[:i]:
				l[i] = (l[i] + 1000) % 10000
	print(same)
	for i in range(n):
		print('%04d' % l[i])


sp = lambda : list(map(int, input().split()))
si = lambda : int(input())
TESTCASES = int(input())
for tc in range(TESTCASES):
	n = si()
	pins = [input() for i in range(n)]
	pinset = set(pins)
	seenset = set()
	changes = 0
	newpins = []
	for pin in pins:
		if pin in seenset:
			for ci in range(40):
				c = ci // 10
				i = ci % 10
				item = pin[:c] + str(i) + pin[c + 1:]
				if item not in pinset:
					pinset.add(item)
					newpins.append(item)
					changes += 1
					break
		else:
			seenset.add(pin)
			newpins.append(pin)
	print(changes)
	print('\n'.join(map(str, newpins)))


def find_code(existing, pin):
	if pin not in existing:
		return pin
	pin = [int(i) for i in list(pin)]
	for i in range(4):
		for j in range(10):
			new_pin = pin
			new_pin[i] = j
			if ''.join([str(k) for k in new_pin]) not in existing:
				return ''.join([str(k) for k in new_pin])
	raise ValueError
t = int(input())
for _ in range(t):
	n = int(input())
	pins = []
	dupes = []
	for _ in range(n):
		pin = input()
		if pin in pins:
			dupes.append(pin)
			pins.append('****')
		else:
			pins.append(pin)
	for _pin in dupes:
		to_add = find_code(pins, _pin)
		for i in range(n):
			if pins[i] == '****':
				pins[i] = to_add
				break
	print(len(dupes))
	for i in pins:
		print(i)


for _ in range(int(input())):
	ar = []
	count = 0
	s1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
	s2 = set({})
	le = int(input())
	for i in range(le):
		x = list(input())
		ar.append(x)
		s2.add(int(x[0]))
	for i in range(le):
		if ar.count(ar[i]) > 1:
			count += 1
			inl = list(s1.difference(s2))[0]
			ar[i][0] = inl
			s2.add(inl)
	print(count)
	for k in ar:
		print(''.join(map(str, k)))


for _ in [0] * int(input()):
	n = int(input())
	a = {}
	b = []
	count = 0
	for i in range(n):
		tmp = int(input())
		if tmp not in a.keys():
			a[tmp] = 0
		a[tmp] += 1
		b.append(tmp)
	for t in range(n):
		j = b[t]
		if a[j] > 1:
			upper = (1 + int(j / 10)) * 10 - 1
			inferior = int(j / 10) * 10
			while a[j] > 1 and upper > j:
				if upper not in a.keys():
					a[upper] = 1
					b[t] = upper
					a[j] -= 1
					count += 1
					break
				upper -= 1
			while upper == j and a[j] > 1 and (inferior < j):
				if inferior not in a.keys():
					a[inferior] = 1
					b[t] = inferior
					a[j] -= 1
					count += 1
					break
				inferior += 1
	print(count)
	for k in b:
		t = k
		if t == 0:
			print('0000')
		else:
			while t < 1000:
				print('0', end='')
				t *= 10
			print(k)


t = int(input())
for quwiw in range(t):
	n = int(input())
	a = []
	k = 0
	for i in range(n):
		a.append(input())
	for i in range(n - 1):
		if a.count(a[i]) == 1:
			continue
		for pos in (-1, -2, -3, -4):
			for j in range(10):
				y = 0
				new = a[i][:pos] + str(j) + (a[i][pos + 1:] if pos != -1 else '')
				if new not in a:
					a[i] = new
					k += 1
					y = 1
				if y == 1:
					break
			if y == 1:
				break
		if y == 1:
			continue
	print(k)
	for i in a:
		if len(str(i)) < 4:
			print(i)
		else:
			print(i)


for _ in range(int(input())):
	d = {}
	n = int(input())
	l = []
	count = 0
	for i in range(n):
		t = input()
		l.append(t)
		if t in d:
			d[t] += 1
		else:
			d[t] = 1
	for i in d:
		count += d[i] - 1
	for i in range(n):
		j = 0
		q = 3
		temp = l[i]
		while l.count(l[i]) > 1:
			s = str(l[i])
			if j >= 10:
				q = 2
				s = str(temp)
			if j >= 20:
				q = 1
				s = str(temp)
			if j > 30:
				q = 0
				s = str(temp)
			t = s[:q] + str((int(s[q]) + 1) % 10) + s[q + 1:]
			j += 1
			l[i] = t
	print(count)
	for i in l:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	p = []
	ans = 0
	s = []
	ss = []
	for i in range(n):
		ss.append(input())
		p.append(list(ss[i]))
		s.append(p[i][3])
	dd = {}
	for i in range(n):
		dd[ss[i]] = dd.get(ss[i], 0) + 1
	x = [str(i) for i in range(10) if str(i) not in s]
	j = 0
	for i in range(n):
		if dd[ss[i]] > 1:
			dd[ss[i]] = dd[ss[i]] - 1
			p[i][3] = x[j]
			ans = ans + 1
			j = j + 1 if j + 1 <= len(x) - 1 else j
	print(ans)
	for i in range(n):
		s = ''
		for j in range(4):
			s = s + p[i][j]
		print(s)


for _ in range(int(input())):
	a = []
	md = 10000
	ct = 0
	for __ in range(int(input())):
		s = int(input())
		a.append(s)
	for i in range(0, len(a)):
		for j in range(i + 1, len(a)):
			if a[i] == a[j]:
				ct += 1
				z = a[j]
				z //= 10
				z *= 10
				k = 0
				while k < 10:
					if z not in a:
						a[j] = z
						break
					z += 1
					k += 1
	print(ct)
	for i in a:
		z = md + i
		z = str(z)
		print(z[1:])


from collections import defaultdict, Counter, deque

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		p = [list(input()) for i in range(n)]
		d = defaultdict(int)
		for i in range(n):
			d[str(p[i])] += 1
		dd = [[0 for i in range(10)] for j in range(4)]
		ansl = [[]] * n
		for i in range(n):
			if d[str(p[i])] == 1:
				for j in range(4):
					dd[j][int(p[i][j])] += 1
				ansl[i] = p[i]
		ans = 0
		dc = defaultdict(int)
		for i in range(n):
			if d[str(p[i])] > 1:
				if dc[str(p[i])] == 0:
					for j in range(4):
						dd[j][int(p[i][j])] += 1
					ansl[i] = p[i]
					dc[str(p[i])] += 1
				else:
					for j in range(4):
						f = False
						for k in range(10):
							if dd[j][k] == 0:
								f = True
								p[i][j] = str(k)
								ansl[i] = p[i]
								dd[j][k] += 1
								ans += 1
								break
						if f:
							break
		print(ans)
		for i in range(len(ansl)):
			print(''.join(map(str, ansl[i])))
main()


def getNext(p, j):
	global orderedpins
	pos = set([i for i in range(10)])
	count = 0
	for pin in orderedpins:
		if int(pin[0]) in pos:
			pos.remove(int(pin[0]))
		if pin == p:
			count += 1
	if count == 1 or pos == set():
		return 0
	letter = pos.pop()
	orderedpins[j][0] = str(letter)
	return 1
for i in range(int(input())):
	n = int(input())
	orderedpins = []
	for j in range(n):
		p = list(input())
		orderedpins.append(p)
	count = 0
	for j in range(n):
		count += getNext(orderedpins[j], j)
	print(count)
	for p in orderedpins:
		print(''.join([str(x) for x in p]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	added = set()
	everything = set(a)
	out = []
	res = 0
	for code in a:
		if code not in added:
			added.add(code)
			out.append(code)
		else:
			res += 1
			done = False
			for i in range(4):
				for d in range(9 + 1):
					nw = code[:i] + str(d) + code[i + 1:]
					if nw not in everything:
						added.add(nw)
						everything.add(nw)
						out.append(nw)
						done = True
						break
				if done:
					break
	print(res)
	print('\n'.join(out))


t = int(input())
for T in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(int(input()))
	count = 0
	num = 0
	for i in range(n):
		l1 = l[:i] + l[i + 1:]
		if l[i] in l1:
			l[i] //= 10
			l[i] *= 10
			for j in range(10):
				if l[i] + j not in l1:
					l[i] += j
					count += 1
					break
	print(count)
	for i in range(n):
		if len(str(l[i])) < 4:
			l[i] = '0' * (4 - len(str(l[i]))) + str(l[i])
		print(l[i])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scanner()
	pincodes = [scanner() for i in range(n)]
	ans = 0
	for i in range(n):
		if pincodes[i] in pincodes[i + 1:]:
			ans += 1
			while pincodes[i] in pincodes[i + 1:] + pincodes[:i]:
				pincodes[i] += 1000
				pincodes[i] %= 10000
	print(ans)
	for x in pincodes:
		print('%04d' % x)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(scanner()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	arr = [[int(x) for x in input()] for _ in range(n)]
	kk = 0
	for i in range(n):
		for j in range(n):
			if i != j:
				if arr[i] == arr[j]:
					for k in range(10):
						if k not in [x[3] for x in arr]:
							arr[i][3] = k
							kk += 1
							break
	print(kk)
	for i in arr:
		print(''.join((str(x) for x in i)))


def solve():
	n = int(input())
	pins = []
	letters = []
	for j in range(n):
		pin = input()
		pins.append(list(pin))
		letters.append(pin[0])
	res = 0
	for a in range(len(pins)):
		if pins.count(pins[a]) >= 2:
			for j in range(0, 10):
				if str(j) not in letters:
					letters.append(str(j))
					pins[a][0] = str(j)
					res += 1
					break
	print(res)
	for pin in pins:
		print(*pin, sep='')
t = int(input())
for i in range(t):
	solve()


y = int(input())
for _ in range(y):
	n = int(input())
	tab = []
	for i in range(n):
		tab.append(input())
	res = 0
	for i in set(tab):
		res += tab.count(i) - 1
	print(res)
	s = set()
	i = 0
	while i < n:
		if tab[i] not in s:
			print(tab[i])
			s.add(tab[i])
		else:
			t = tab[i]
			for j in range(4):
				f = 0
				for k in range(10):
					h = t[:j] + str(k) + t[j + 1:]
					if h not in s and h not in tab[i:]:
						print(h)
						s.add(h)
						tab[i] = h
						f = 1
						break
				if f:
					break
		i += 1


from itertools import groupby

def find_f():
	for (el, c) in free.items():
		if c == 0:
			return el

def A():
	global free
	n = int(input())
	cods = [(input(), i) for i in range(n)]
	free = {str(i): 0 for i in range(10)}
	for pin in cods:
		free[pin[0][0]] += 1
	grops = groupby(sorted(cods), key=lambda x: x[0])
	ans = [0] * n
	cnt = 0
	for grop in grops:
		for (i, smt) in enumerate(grop[1]):
			(pin, ind) = smt
			if i == 0:
				ans[ind] = pin
			else:
				free[pin[0]] -= 1
				a = find_f()
				pin = a + pin[1:]
				free[a] += 1
				ans[ind] = pin
				cnt += 1
	print(cnt)
	for g in ans:
		print(g)

def main():
	t = int(input())
	for _ in range(t):
		A()
main()


t = int(input())
for _ in range(t):
	n = int(input())
	count = {}
	a = []
	change = 0
	for i in range(n):
		s = input()
		a.append(s)
		if s in count:
			count[s] += 1
		else:
			count[s] = 1
	for i in range(n):
		if count[a[i]] > 1:
			temp = a[i][0:3]
			num = 0
			while True:
				if temp + str(num) not in count:
					count[temp + str(num)] = 1
					count[a[i]] -= 1
					a[i] = temp + str(num)
					change += 1
					break
				num += 1
	print(change)
	for i in a:
		print(i)


t = int(input())
for j in range(t):
	n = int(input())
	lst = [int(input()) for x in range(n)]
	count = 0
	for i in range(n):
		if lst[i] in lst[i + 1:]:
			count += 1
			while lst[i] in lst[i + 1:] + lst[:i]:
				lst[i] = (lst[i] + 1000) % 10000
	print(count)
	for i in range(n):
		print('%04d' % lst[i])


t = int(input())
for zz in range(t):
	n = int(input())
	p = []
	for i in range(n):
		p.append(input())
	d = {}
	for i in p:
		try:
			d[i] += 1
		except:
			d[i] = 1
	k = 0
	for v in d.values():
		k += v - 1
	print(k)
	s = set(p)
	for i in range(len(p)):
		if d[p[i]] > 1:
			d[p[i]] -= 1
			cop = p[i]
			while len(cop) <= 3:
				cop.insert(0, 0)
			po = 0
			c = 9
			st = True
			while st:
				p[i] = list(cop)
				p[i][po] = str(c)
				p[i] = ''.join(p[i])
				c -= 1
				if p[i] not in s:
					st = False
				if c == 0:
					c = 9
					po += 1
			s = set(p)
	for i in p:
		print(i)


n = int(input())
digs = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

def replace(string, index, char):
	string += ' '
	s = string[0:index] + char + string[index + 1:]
	return s.rstrip()

def getAns(k):
	pins = []
	newpins = []
	count = 0
	for j in range(k):
		pins.append(input())
	for a in range(k):
		flag = False
		theSet = set(pins).union(newpins)
		if pins[a] not in newpins:
			newpins.append(pins[a])
		else:
			for b in range(4):
				for c in range(10):
					x = replace(pins[a], b, digs[c])
					if x not in theSet:
						newpins.append(x)
						count += 1
						flag = True
						break
				if flag:
					break
	print(count)
	for thing in newpins:
		print(thing)
for i in range(n):
	getAns(int(input()))


from sys import stdin

def input():
	return stdin.readline()[:-1]
for _ in range(int(input())):
	n = int(input())
	digitschanged = 0
	allwords = set()
	storedwords = set()
	output = []
	inputs = []
	for i in range(n):
		inputs.append(int(input()))
		allwords.add(inputs[i])
	for i in range(n):
		s = inputs[i]
		if i == 0:
			storedwords.add(s)
			output.append(s)
			continue
		if s not in storedwords:
			storedwords.add(s)
			output.append(s)
		else:
			dig = 0
			while s in allwords and dig <= 9:
				s //= 10
				s *= 10
				s += dig
				dig += 1
			storedwords.add(s)
			allwords.add(s)
			output.append(s)
			digitschanged += 1
	print(digitschanged)
	for num in output:
		l = [0, 0, 0, 0]
		l[3] = num % 10
		num //= 10
		l[2] = num % 10
		num //= 10
		l[1] = num % 10
		num //= 10
		l[0] = num % 10
		l = list(map(str, l))
		print(''.join(l))


def f():
	n = int(input())
	P = []
	for i in range(n):
		P.append([int(s) for s in input()])
	order = list(range(n))
	order.sort(key=lambda x: P[x])
	ind = [0] * n
	for i in range(n):
		ind[order[i]] = i
	P.sort()

	def reset(start, end):
		if end - start <= 0:
			return 0
		chan = 0
		chosen = [0] * 10
		for i in range(start, end + 1):
			d = P[i][3]
			chosen[d] += 1
		for i in range(start, end + 1):
			d = P[i][3]
			if chosen[d] > 1:
				for dt in range(10):
					if not chosen[dt]:
						P[i][3] = dt
						chosen[dt] += 1
						chosen[d] -= 1
						chan += 1
						break
		return chan
	last3 = [-1, -1, -1]
	change = 0
	start = 0
	end = 0
	for (i, p) in enumerate(P):
		if p[:3] == last3:
			end = i
		else:
			change += reset(start, end)
			last3 = p[:3]
			start = i
	change += reset(start, end)
	print(change)
	for i in ind:
		print(''.join((str(d) for d in P[i])))
T = int(input())
for t in range(T):
	f()


t = int(input())
for _ in range(t):
	n = int(input())
	numbers = []
	prefixes = set([str(x) for x in range(10)])
	for _ in range(n):
		s = input()
		numbers.append(s)
		prefixes.discard(s[0])
	changes = 0
	for (index, number) in enumerate(numbers):
		if number in numbers[:index]:
			prefix = prefixes.pop()
			numbers[index] = f'{prefix}{numbers[index][1:]}'
			changes += 1
	print(changes)
	for s in numbers:
		print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	c = []
	p = []
	for i in range(n):
		o = list(input())
		c.append(o)
	changes = 0
	for i in range(len(c) - 1):
		flag = 0
		if c[i] in c[i + 1:] or c[i] in c[:i]:
			for j in range(4):
				for k in range(1, 10):
					l = c[i][j]
					c[i][j] = str(k)
					if c[i] not in c[i + 1:] and c[i] not in c[:i]:
						flag += 1
						changes += 1
						break
					else:
						c[i][j] = l
				if flag == 1:
					break
	print(changes)
	for i in range(len(c)):
		print(''.join(c[i]))


for _ in range(int(input())):
	n = int(input())
	p = []
	for i in range(n):
		p.append(input())
	ans = 0
	for (i, c) in enumerate(p):
		j = 0
		while c in p[:i] + p[i + 1:]:
			c = c[:3] + str(j)
			j += 1
		ans += p[i] != c
		p[i] = c
	print(ans)
	for i in range(n):
		print(p[i])


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] * 9999
	ans_list = []
	ans = 0
	for i in range(n):
		pin = int(input())
		a[pin] += 1
		ans_list.append(pin)
	for roentail in range(len(ans_list)):
		i = ans_list[roentail]
		if a[i] > 1:
			ans += 1
			j = 1
			while a[i // 10 * 10 + (i % 10 + j) % 10]:
				j += 1
			a[i] -= 1
			a[i // 10 * 10 + (i % 10 + j) % 10] = 1
			ans_list[roentail] = i // 10 * 10 + (i % 10 + j) % 10
	print(ans)
	for i in ans_list:
		print('{:04}'.format(i))


tc = int(input())
for _ in range(tc):
	n = int(input().strip())
	order = []
	for _ in range(n):
		order.append(input())
	arr = set(order)
	ret = {}
	the_way = set()
	ans = 0
	ans_list = []
	for num in order:
		if num in the_way:
			ans += 1
			for i in range(10):
				num_str = num
				tmp3 = str(i) + num_str[1:]
				if tmp3 not in the_way and tmp3 not in arr:
					ans_list.append(tmp3)
					the_way.add(tmp3)
					break
				tmp3 = num[0:1] + str(i) + num_str[2:]
				if tmp3 not in the_way and tmp3 not in arr:
					ans_list.append(tmp3)
					the_way.add(tmp3)
					break
				tmp3 = num[0:2] + str(i) + num_str[3:]
				if tmp3 not in the_way and tmp3 not in arr:
					ans_list.append(tmp3)
					the_way.add(tmp3)
					break
				tmp3 = num[0:3] + str(i)
				if tmp3 not in the_way and tmp3 not in arr:
					ans_list.append(tmp3)
					the_way.add(tmp3)
					break
		else:
			ans_list.append(num)
			the_way.add(num)
	print(ans)
	for x in ans_list:
		print(x)


for _ in range(int(input())):
	N = int(input())
	card = {}
	t = []
	for i in range(N):
		q = input()
		if q not in card:
			card[q] = 1
		else:
			card[q] += 1
		t.append(q)
	cnt = 0
	for i in range(N):
		if card[t[i]] == 1:
			continue
		if card[t[i]] > 1:
			card[t[i]] -= 1
			cnt += 1
		for x in range(4):
			flag = False
			c = list(t[i])
			for y in range(0, 10):
				c[x] = str(y)
				new = ''.join(c)
				if new not in card:
					card[new] = 1
					t[i] = new
					flag = True
					break
			if flag:
				break
	print(cnt)
	print(*t, sep='\n')


from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd, ceil, factorial
from heapq import heapify, heappush, heappop
MOD = 10 ** 9 + 7
inf = float('inf')
ans_ = []

def nin():
	return int(input())

def ninf():
	return int(file.readline())

def st():
	return input().strip()

def stf():
	return file.readline().strip()

def read():
	return list(map(int, input().strip().split()))

def readf():
	return list(map(int, file.readline().strip().split()))
ans_ = []

def solve():
	for _ in range(nin()):
		n = nin()
		arr = [st() for i in range(n)]
		inds = defaultdict(list)
		s = set([i for i in '0123456789'])
		for i in range(n):
			if arr[i][0] in s:
				s.remove(arr[i][0])
			if not arr[i] in inds:
				inds[arr[i]] = i
		s = list(s)
		c = 0
		for i in range(n):
			if not i in inds.values():
				arr[i] = s.pop() + arr[i][1:]
				c += 1
		print(c)
		for i in arr:
			print(i)
solve()
for i in ans_:
	print(i)


def solve():
	n = int(input())
	num = []
	for i in range(n):
		ss = input()
		num.append(ss)
	cnt = 0
	for i in range(n):
		if num[i] in num[i + 1:]:
			cnt += 1
			j = 0
			while num[i] in num[:i] + num[i + 1:]:
				num[i] = num[i][:3] + str(j)
				j += 1
	print(cnt)
	print(*num, sep='\n')
t = int(input())
for i in range(t):
	solve()


from collections import deque

def bfs(to_change, used_pins, starters):
	fringe = deque()
	fringe.append((to_change, 0))
	if to_change not in used_pins:
		return fringe[0]
	while len(fringe) > 0:
		(cur, changes) = fringe.popleft()
		cur_children = []
		for n in range(10):
			cur_children.append(cur[:changes] + str(n) + cur[changes + 1:])
		for c in cur_children:
			if c in used or c in starters:
				fringe.append((c, changes + 1))
			else:
				return (c, changes + 1)
T = int(input())
for t in range(T):
	N = int(input())
	pins = {}
	for n in range(N):
		pin = input().strip()
		if pin in pins:
			pins[pin].append(n)
		else:
			pins[pin] = [n]
	new_pins = [None] * N
	original = {x for x in pins.keys()}
	num_changes = 0
	used = set()
	for cur_pin in pins:
		for index in pins[cur_pin]:
			(new_pin, new_changes) = bfs(cur_pin, used, original)
			new_pins[index] = new_pin
			num_changes += new_changes
			used.add(new_pin)
	print(num_changes)
	for new_pin in new_pins:
		print(new_pin)


for _ in range(int(input())):
	n = int(input())
	lis = []
	for i in range(n):
		p = input()
		lis.append(int(p))
	ans = 0
	for i in range(n - 1):
		if lis[i] in lis[i + 1:]:
			ans += 1
			while lis[i] in lis[:i] + lis[i + 1:]:
				lis[i] += 1000
				lis[i] %= 10000
	print(ans)
	for i in lis:
		print('%04d' % int(i))


for _ in range(int(input())):
	n = int(input())
	dp = dict()
	l = list()
	for i in range(n):
		p = input()
		if p in dp.keys():
			dp[p] += 1
		else:
			dp[p] = 1
		l.append(p)
	ans = 0
	for i in dp.keys():
		if dp[i] > 1:
			ans += dp[i] - 1
	print(ans)
	for i in range(n):
		if l.count(l[i]) > 1:
			temp = list(str(l[i]))
			j = 0
			while j <= 9 and l.count(''.join(temp)) > 0:
				temp[0] = str(j)
				j += 1
			l[i] = ''.join(temp)
	for i in l:
		print(i)


def changenum(number, index, toDigit):
	newnumber = number[:index] + toDigit + number[index + 1:]
	return newnumber
t = int(input())
for titer in range(t):
	n = int(input())
	pins = []
	changes = 0
	for niter in range(n):
		pin = str(input())
		pins.append(pin)
	for iiter in range(n - 1):
		for jiter in range(iiter + 1, n):
			if pins[jiter] == pins[iiter]:
				changes += 1
				for k in range(0, 4):
					for sumiter in range(1, 10):
						newnumber = changenum(pins[jiter], k, str((int(pins[jiter][k]) + sumiter) % 10))
						if pins.count(newnumber) == 0:
							pins.pop(jiter)
							pins.insert(jiter, newnumber)
							break
					if pins.count(newnumber) == 1:
						break
	print(changes)
	for printiter in range(n):
		print(pins[printiter])


q = int(input())
for l in range(q):
	n = int(input())
	pins = []
	t = 0
	isset = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
	for j in range(n):
		pins.append(list(map(int, list(input()))))
	for i in range(4):
		for j in range(n):
			if pins[j][i] in isset[i]:
				isset[i].remove(pins[j][i])
	for i in range(n):
		for j in range(n):
			if pins[j] == pins[i] and j != i:
				pins[j][0] = isset[0][0]
				isset[0].remove(pins[j][0])
				t += 1
	print(t)
	for k in range(len(pins)):
		print(''.join(list(map(str, pins[k]))))


def solve():
	n = int(input())
	d = {}
	ss = [input() for i in range(n)]
	for s in ss:
		d[s] = d.get(s, 0) + 1
	ans = sum((i - 1 for i in d.values()))
	print(ans)
	used = set(d.keys())
	l = []
	for s in ss:
		if d[s] > 1:
			t = list(s)
			f = False
			for i in range(4):
				for j in range(10):
					t[i] = str(j)
					u = ''.join(t)
					if u not in used:
						l.append(u)
						used.add(u)
						d[s] -= 1
						f = True
						break
				if f:
					break
		else:
			l.append(s)
			used.add(s)
	print(*l, sep='\n')
t = int(input())
for i in range(t):
	solve()


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	cnt = {}
	inp = []
	n = int(input())
	for __ in range(n):
		inp.append(input().strip('\n'))
		cnt[inp[-1]] = cnt.get(inp[-1], 0) + 1
	ans = 0
	for i in range(n):
		if cnt[inp[i]] != 1:
			ans += 1
			cnt[inp[i]] -= 1
			for j in range(10):
				if cnt.get(inp[i][:-1] + str(j), 0) == 0:
					inp[i] = inp[i][:-1] + str(j)
					break
			cnt[inp[i]] = 1
	print(ans, '\n'.join(inp), sep='\n')


from sys import stdin, stdout
from collections import defaultdict, deque

def check(index):
	num = card[index]
	for i in range(len(card)):
		if i != index and num == card[i]:
			return True
	return False

def transform(num):
	return ''.join(num)
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	card = []
	for __ in range(n):
		card.append(stdin.readline().strip())
	change = 0
	for i in range(n):
		if check(i):
			change += 1
			num = list(card[i])
			for j in range(4):
				if check(i):
					for k in range(10):
						num[j] = str(k)
						if transform(num) in card:
							continue
						else:
							card[i] = transform(num)
							break
	print(change)
	for i in card:
		print(i)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	li = []
	ans = 0
	l = []
	for i in range(n):
		x = z()
		if x not in li:
			li.append(x)
		else:
			ans += 1
			l.append(x)
			li.append(x)
	print(ans)
	ll = set()
	for i in li:
		if i not in ll:
			print(i)
			ll.add(i)
			continue
		lx = list(i)
		c = 0
		for k in range(4):
			for p in range(10):
				lx[k] = str(p)
				t = lx[0] + lx[1] + lx[2] + lx[3]
				if t not in ll and t not in li:
					print(t)
					ll.add(t)
					c = 1
					break
			if c == 1:
				break


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	l = list()
	for i in range(0, n):
		a = input()
		l.append(str(a))
	d = defaultdict(lambda : [])
	for i in range(0, 4):
		for j in range(0, n):
			d[i] = list(set(d[i] + [l[j][i]]))
	ans = 0
	m = list()
	for i in range(0, n):
		if l.count(l[i]) > 1:
			ans = ans + 1
			for j in range(0, 10):
				if str(j) not in d[0]:
					d[0] = d[0] + [str(j)]
					s = str(j) + l[i][1:]
					m.append(s)
					l[i] = s
					break
	print(ans)
	for i in range(0, n):
		print(l[i])


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
from itertools import permutations
MOD = pow(10, 9) + 7
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')
for _ in range(int(input())):
	n = int(input())
	l = [int(input()) for i in range(n)]
	d = {}
	for i in l:
		d[i] = d.get(i, 0) + 1
	r = []
	c = 0
	for i in range(n):
		if d[l[i]] > 1:
			val = l[i] // 10 * 10
			while True:
				if d.get(val, 0) == 0:
					break
				val += 1
			d[val] = d.get(val, 0) + 1
			r.append(val)
			c += 1
			d[l[i]] -= 1
		else:
			r.append(l[i])
	print(c)
	for i in r:
		print('0' * (4 - len(str(i))) + str(i))


t = int(input())
for i in range(t):
	s = []
	n = int(input())
	for j in range(n):
		l = input()
		s.append(l)
	c = 0
	for j in range(n):
		if s[j] in s[:j] or s[j] in s[j + 1:]:
			c += 1
			s1 = int(s[j])
			f = 0
			while s[j] in s[:j] or s[j] in s[j + 1:]:
				if s1 % 10 == 0:
					s1 += 1
					f = 1
				elif s1 % 10 == 9:
					s1 -= 1
				elif f == 0:
					s1 -= 1
				else:
					s1 += 1
				if len(str(s1)) == 4:
					s[j] = str(s1)
				else:
					s[j] = '0' * (4 - len(str(s1))) + str(s1)
		else:
			continue
	print(c)
	for j in range(n):
		print(s[j])


for _ in range(int(input())):
	n = int(input())
	a = []
	change = 0
	d = [int(x) for x in '0123456789']
	for i in range(n):
		inp = input()
		a.append(inp)
		if int(inp[3]) in d:
			d.remove(int(inp[3]))
	for i in range(n - 1):
		for j in range(i + 1, n):
			if a[i] == a[j]:
				s = a[j][:3] + str(d[0])
				a[j] = s
				d.remove(d[0])
				change += 1
	print(change)
	for i in range(n):
		print(a[i])


import os
import sys

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		(c, ans) = solve(N, [read_int() for _ in range(N)])
		print(c)
		for a in ans:
			print('{:04}'.format(a))

def solve(N, P):
	d = {}
	for p in P:
		if p not in d:
			d[p] = 0
		d[p] += 1
	c = 0
	ans = []
	for p in P:
		if d[p] == 1:
			ans.append(p)
			continue
		c += 1
		np = -1
		a = [p % 10, p // 10 % 10, p // 100 % 10, p // 1000]
		for i in range(4):
			for j in range(10):
				if a[i] == j:
					continue
				orig = a[i]
				a[i] = j
				v = a[0] + a[1] * 10 + a[2] * 100 + a[3] * 1000
				if v not in d:
					np = v
					break
				a[i] = orig
			if np != -1:
				break
		ans.append(np)
		d[p] -= 1
		d[np] = 1
	return (c, ans)
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


t = int(input())
for case_num in range(t):
	n = int(input())
	pin = []
	cnt = dict()
	for i in range(n):
		pin.append(input())
		if pin[i] in cnt:
			cnt[pin[i]].append(i)
		else:
			cnt[pin[i]] = [i]
	ans = 0
	updated = cnt.copy()
	for key in cnt:
		if len(cnt[key]) > 1:
			dup = len(cnt[key]) - 1
			ans += dup
			for i in range(dup):
				for tail in range(10):
					new = pin[cnt[key][i]][0:3] + str(tail)
					if not new in updated:
						pin[cnt[key][i]] = new
						updated[new] = []
						break
	print(ans)
	for key in pin:
		print(key)


t = int(input())
out = []
for _ in range(t):
	n = int(input())
	l = []
	count = 0
	bad = [False] * n
	for __ in range(n):
		pin = input()
		if pin in l:
			count += 1
			bad[__] = True
		l.append(pin)
	out.append(str(count))
	for i in range(n):
		if bad[i]:
			short = l[i][0:3]
			for c in '0123456789':
				if short + c not in l:
					l[i] = short + c
					break
		out.append(l[i])
print('\n'.join(out))


import sys
from collections import Counter
reader = (int(s.rstrip()) for s in sys.stdin)

def codes(a):
	used = Counter(a)
	ans = []
	changes = 0
	for code in a:
		new = code
		if used[new] > 1:
			changes += 1
			used[new] -= 1
			while new in used and new % 10 > 0:
				new -= 1
			if new in used:
				new = code
				while new in used and new % 10 < 9:
					new += 1
		used[new] += 1
		ans.append(new)
	return (changes, [str(c).rjust(4, '0') for c in ans])
t = next(reader)
for i in range(t):
	n = next(reader)
	a = [next(reader) for j in range(n)]
	(ctr, ans) = codes(a)
	print(ctr)
	[print(code) for code in ans]


from itertools import product
t = int(input())
for _ in range(t):
	n = int(input())
	A = []
	result = 0
	for _ in range(n):
		A += [input()]
	for i in range(n):
		if any([A[j] == A[i] for j in range(i)]):
			result += 1
			for (k, p) in product(range(4), '0123456789'):
				b = list(A[i])
				b[k] = p
				if all([list(A[j]) != b for j in range(n)]):
					A[i] = ''.join(b)
					break
	print(result)
	for pin in A:
		print(pin)


def chg(x):
	if x[3] == '9':
		return x[:3] + '0'
	else:
		return x[:3] + chr(ord(x[3]) + 1)
T = int(input())
for kase in range(T):
	n = int(input())
	lis = []
	cnt = 0
	for i in range(n):
		lis.append(input())
	for i in range(n):
		if lis[i] in lis[:i] or lis[i] in lis[i + 1:]:
			cnt += 1
		while lis[i] in lis[:i] or lis[i] in lis[i + 1:]:
			lis[i] = chg(lis[i])
	print(cnt, *lis, sep='\n')


def withZeros(m):
	t = str(m)
	if m < 1000:
		t = '0' + t
		if m < 100:
			t = '0' + t
			if m < 10:
				t = '0' + t
	return t
q = int(input())
for query in range(q):
	n = int(input())
	r = [0 for i in range(n)]
	for i in range(n):
		r[i] = int(input())
	w = [r[i] % 1000 for i in range(n)]
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			if r[i] == r[j]:
				ans += 1
				for a in range(10):
					if (r[i] + a * 1000 + 1000) % 10000 not in r:
						r[i] = (r[i] + a * 1000 + 1000) % 10000
						break
	print(ans)
	for i in range(n):
		print(withZeros(r[i]))


def solve(pins):
	set_pins = set(pins)
	if len(set_pins) == len(pins):
		return (0, pins)
	else:
		for i in range(n):
			j = 0
			while pins.count(pins[i]) > 1:
				pins[i] = pins[i][:3] + str(j)
				j += 1
		return (len(pins) - len(set_pins), pins)
t = int(input())
for _ in range(t):
	n = int(input())
	pins = []
	for _ in range(n):
		pins.append(input())
	(num_changes, set_changes) = solve(pins)
	print(num_changes)
	for x in set_changes:
		print(x)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
t = I()
for i in range(0, t):
	n = int(input())
	a = []
	c = 0
	d = defaultdict(int)
	for i in range(0, n):
		s = input()
		s = s[:len(s) - 1]
		a.append(s)
		d[s] += 1
	for i in range(0, n):
		if d[a[i]] > 1:
			s = a[i]
			for j in range(0, 10):
				x = str(j) + s[1:]
				if x not in d.keys():
					d[x] += 1
					c += 1
					d[a[i]] -= 1
					a[i] = x
					break
	print(c)
	for i in a:
		print(i)


q = int(input())
for q1 in range(q):
	n = int(input())
	count = 0
	dic = {}
	lista_pins = []
	pre_lista = []
	for n1 in range(n):
		pin = int(input())
		pre_lista.append(pin)
	for pin in pre_lista:
		if pin in dic:
			pin = pin // 10 * 10
			while pin in dic or pin in pre_lista:
				pin += 1
			dic[pin] = 1
			count += 1
		else:
			dic[pin] = 1
		lista_pins.append(pin)
	print(count)
	for pin in lista_pins:
		print('%04d' % pin)


t = int(input())
for querrie in range(t):
	mymystring = ''
	total = 0
	cards = []
	counter = 0
	numofcards = int(input())
	for card in range(numofcards):
		mylist = []
		mystring = input()
		for character in mystring:
			mylist.append(int(character))
		cards.append(mylist)
	for card in range(numofcards):
		for card2 in range(numofcards):
			if card != card2:
				if cards[card] == cards[card2]:
					total = total + 1
					orignal = cards[card][3]
					while cards.count(cards[card]) > 1 and counter < 3:
						if cards[card][3] == 9:
							while cards.count(cards[card]) > 1 and cards[card][3] != 0:
								cards[card][3] = cards[card][3] - 1
						else:
							while cards.count(cards[card]) > 1 and cards[card][3] != 9:
								cards[card][3] = cards[card][3] + 1
	print(total)
	for card in range(numofcards):
		mymystring = ''
		for num in cards[card]:
			mymystring = mymystring + str(num)
		print(mymystring)


def digits(n):
	count = 0
	while n > 0:
		count += 1
		n = n // 10
	return count
t = int(input())
for you in range(t):
	n = int(input())
	l = []
	arr = [0 for i in range(10)]
	count = 0
	for i in range(n):
		x = input()
		arr[int(x[3])] += 1
		l.append(x)
	for i in range(n):
		k = l[i]
		p = list(k)
		if k in l[i + 1:n]:
			count += 1
			for j in range(10):
				if arr[j] == 0:
					break
			p[3] = chr(j + 48)
			arr[j] += 1
			l[i] = ''.join(p)
		else:
			continue
	print(count)
	for i in l:
		print(i)


t = int(input())
for m in range(t):
	n = int(input())
	l = []
	ans = 0
	for i in range(n):
		f = input()
		l.append(f)
	for i in range(n):
		if l[i] in l[i + 1:]:
			ans = ans + 1
			j = 0
			while l[i] in l[i + 1:] + l[:i]:
				l[i] = l[i][0:3] + str(j)
				j = j + 1
	print(ans)
	for i in l:
		print(i)


def chenge(a, se):
	for i in range(len(a)):
		for j in range(9 + 1):
			copyR = a[i]
			a[i] = str(j)
			if ''.join(a) not in se:
				return a
			a[i] = copyR
t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		a.append(list(input()))
	se = set()
	se.add(''.join(a[0]))
	ans = [''.join(a[0])]
	ansSum = 0
	newSe = set()
	for i in range(len(a)):
		newSe.add(''.join(a[i]))
	for j in range(1, len(a)):
		if ''.join(a[j]) in se:
			ans.append(chenge(a[j], newSe))
			se.add(''.join(ans[-1]))
			newSe.add(''.join(ans[-1]))
			ansSum += 1
		else:
			ans.append(a[j])
			se.add(''.join(ans[-1]))
	print(ansSum)
	for j in range(len(ans)):
		print(''.join(ans[j]))


t = int(input())
for _ in range(t):
	n = int(input())
	k = []
	for i in range(n):
		k.append(input())
	total = 0
	for i in range(n):
		count = 0
		for j in range(n):
			if k[i] == k[j]:
				count += 1
		if count > 1:
			temp = k[i]
			for a in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
				if a + k[i][1:] not in k:
					k[i] = a + k[i][1:]
					break
			if temp == k[i]:
				for a in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
					if k[i][0] + a + k[i][2:] not in k:
						k[i] = a + k[i][1:]
						break
			total += 1
	print(total)
	for i in range(n):
		print(k[i])


for _ in range(int(input())):
	n = int(input())
	ans = []
	ps = [input() for _ in range(n)]
	suf = {}
	for i in range(n):
		p = ps[i]
		s = p[1:]
		if s not in suf:
			suf[s] = [str(A) for A in range(10)]
		if p[0] in suf[s]:
			suf[s].remove(p[0])
	cnt = 0
	used = {}
	for i in range(n):
		p = ps[i]
		s = p[1:]
		if s in used and p[0] in used[s]:
			p = suf[s][-1] + s
			cnt += 1
			suf[s].pop()
		used.setdefault(s, set()).add(p[0])
		ans.append(p)
	print(cnt)
	print(*ans, sep='\n')


t = int(input())
for i in range(t):
	l1 = [0] * 10
	n = int(input())
	l2 = []
	k = 0
	m = [0] * n
	for i in range(n):
		e = int(input())
		l1[int(e / 1000)] = 1
		if e in l2:
			m[i] = 1
		l2.append(e)
	for i in range(n):
		if m[i] == 1:
			k += 1
			for j in range(10):
				if l1[j] != 1:
					l2[i] = l2[i] % 1000 + j * 1000
					l1[j] = 1
					break
	print(k)
	for i in range(n):
		if int(l2[i] / 10) == 0:
			print('000' + str(l2[i]))
		elif int(l2[i] / 100) == 0:
			print('00' + str(l2[i]))
		elif int(l2[i] / 1000) == 0:
			print('0' + str(l2[i]))
		else:
			print(l2[i])


y = int(input())
while y:
	y -= 1
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	s = []
	t = []
	z = 0
	for i in range(n):
		if not a[i] in s:
			s.append(a[i])
		else:
			z += 1
			t.append(i)
	for i in range(z):
		k = t[i]
		c = a[k]
		x = 0
		while c in a:
			c = str(x) + c[1:]
			x += 1
		a[k] = c
	print(z)
	for i in a:
		print(i)


q = int(input())
for i in range(q):
	w = int(input())
	e = [list(input()) for j in range(w)]
	ans = 0
	for j in range(w):
		r = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		for k in range(w):
			if e[j][:3] == e[k][:3] and j != k:
				if e[k][-1] in r:
					r.remove(e[k][-1])
		for k in range(w):
			if e[j] == e[k] and j != k:
				e[k][-1] = r.pop()
				ans += 1
	print(ans)
	for j in e:
		for k in j:
			print(k, end='')
		print()


t = int(input())
while t:
	t += -1
	n = int(input())
	l = []
	for i in range(n):
		l.append(input())
	count = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if l[i] == l[j]:
				temp = list(l[i])
				for k in range(0, 10):
					temp[3] = str(k)
					s = ''.join(temp)
					check = 0
					for h in range(n):
						if l[h] == s:
							check = 1
							break
					if check == 0:
						count -= -1
						l[i] = s
						break
	print(count)
	for i in l:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	pins = {}
	arr = []
	for i in range(n):
		e = input()
		arr.append(e)
		try:
			pins[e] += 1
		except KeyError:
			pins[e] = 1
	cnt = 0
	new = {}
	ind = {}
	for i in pins:
		cnt += pins[i] - 1
		while pins[i] != 1:
			p = list(i)
			k = 0
			done = False
			while k < 4:
				for j in range(10):
					p[k] = str(j)
					if ''.join(p) not in pins and ''.join(p) not in new:
						done = True
						new[''.join(p)] = 1
						pins[i] -= 1
						break
				if done:
					break
	print(cnt)
	for i in arr:
		if i in pins:
			print(i)
			del pins[i]
		else:
			for j in range(10):
				if str(j) + i[1:] in new:
					print(str(j) + i[1:])
					del new[str(j) + i[1:]]
					break
				elif i[0] + str(j) + i[2:] in new:
					print(i[0] + str(j) + i[2:])
					del new[i[0] + str(j) + i[2:]]
					break


for _ in range(int(input())):
	n = int(input())
	l = list()
	for i in range(n):
		l.append(input())
	c = 0
	for i in range(n):
		x = l[i]
		if x in l[0:i] or x in l[i + 1:]:
			y = 0
			f = 0
			while y < 4:
				for z in range(10):
					p = x[0:y] + str(z) + x[y + 1:]
					if p not in l[0:i] and p not in l[i + 1:]:
						l[i] = p
						c += 1
						f = 1
						break
				if f == 1:
					break
				y += 1
	print(c)
	for i in l:
		print(i)


import sys
FOR_SUBMIT = True
readline = sys.stdin.readline
old_print = print

def print(i):
	if not FOR_SUBMIT:
		old_print(i)

def has_conflict(nums, i):
	for (j, n) in enumerate(nums):
		if j != i:
			if n == nums[i]:
				return True
	return False

def mutate(nums, i):
	original = nums[i]
	for digit in range(4):
		for number in range(10):
			nums[i][digit] = str(number)
			if not has_conflict(nums, i):
				return
		nums[i] = original

def solve(nums):
	mutation = 0
	for i in range(len(nums)):
		if has_conflict(nums, i):
			mutate(nums, i)
			mutation += 1
	old_print(mutation)
	for n in nums:
		old_print(''.join(n))
T = int(readline())
for _ in range(T):
	N = int(readline())
	nums = [list(readline().strip()) for x in range(N)]
	solve(nums)


q = int(input())
for _ in range(q):
	n = int(input())
	arr = []
	k = 0
	for _ in range(n):
		a = input()
		if a in arr:
			k += 1
		arr.append(a)
	print(k)
	for t in range(n):
		if arr[0:t + 1].count(arr[t]) == 1:
			pass
		else:
			z = 0
			while arr.count(arr[t]) != 1:
				arr[t] = arr[t][0:3] + str(z)
				z += 1
		print(arr[t])


from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	la = []
	hash = defaultdict(int)
	seti = set()
	for i in range(n):
		la.append(input())
		hash[la[i]] += 1
		seti.add(la[i])
	ans = []
	set1 = set()
	cnt = 0
	for i in la:
		if hash[i] > 1:
			for j in range(4):
				s = list(i)
				flag = 0
				for k in range(10):
					s[j] = str(k)
					za = ''.join(s)
					if za not in seti and za not in set1:
						flag = 1
						hash[i] -= 1
						ans.append(za)
						set1.add(za)
						cnt += 1
						break
				if flag == 1:
					break
		else:
			ans.append(i)
			hash[i] -= 1
	print(cnt)
	print('\n'.join(ans))


import collections
for t in range(int(input())):
	n = int(input())
	p = [input() for i in range(n)]
	ans = 0
	for i in range(n):
		if p[i] in p[i + 1:]:
			for j in range(10):
				code = p[i][:3] + str(j)
				if code not in p:
					p[i] = code
					ans += 1
					break
	print(ans)
	for code in p:
		print(code)


import random
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	cards = []
	card_set = set()
	for s in range(n):
		cards.append(input().strip())
	card_set2 = set(cards)
	ans = 0
	ans_cards = []
	for pin in cards:
		try:
			card_set2.remove(pin)
		except KeyError:
			pass
		temppin = pin
		while temppin in card_set or temppin in card_set2:
			pinint = list(pin)
			pinint[random.randint(0, 3)] = str(random.randint(0, 9))
			temppin = ''.join(pinint)
		card_set.add(temppin)
		ans_cards.append(temppin)
		if temppin != pin:
			ans += 1
	print(len(cards) - len(set(cards)))
	for card in ans_cards:
		print(card)


from collections import defaultdict
from itertools import permutations
per = []
for i in range(1000, 10000):
	per.append(str(i))
test = int(input())
for _ in range(test):
	n = int(input())
	s = []
	for word in range(n):
		s.append(input())
	ans = 0
	mp = defaultdict(lambda : 0)
	for word in s:
		mp[word] += 1
	for (key, val) in enumerate(s):
		if key == 0:
			continue
		elif mp[val] == 1:
			mp[val] = 1
			continue
		else:
			score = (5, '')
			for (key2, val2) in enumerate(per):
				if mp[val2] != 0:
					continue
				num = sum((1 if val[key3] != val3 else 0 for (key3, val3) in enumerate(val2)))
				if num < score[0]:
					score = (num, val2)
			mp[score[-1]] = 1
			mp[val] -= 1
			ans += score[0]
			s[key] = score[-1]
	print(ans)
	for word in s:
		print(word)


for _ in range(int(input())):
	n = int(input())
	l = [input() for i in range(n)]
	s = set()
	for i in l:
		s.add(int(i))
	k = 0
	for i in range(n):
		x = l[i]
		flag = False
		for j in range(i + 1, n):
			if x != l[j]:
				continue
			else:
				k += 1
				val = int(x) - int(x) % 10
				limit = int(x) + 10 - int(x) % 10
				if val == 0:
					val = 1
				for z in range(val, limit + 1, 1):
					if z not in s:
						if len(str(z)) < 4:
							z = '0' * (4 - len(str(z))) + str(z)
						l[j] = str(z)
						s.add(int(z))
						break
	print(k)
	for i in range(n):
		print(l[i])


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	d = {}
	s = 0
	for i in range(n):
		temp = input()
		if d.get(temp):
			d[temp] += 1
			s += 1
		else:
			d[temp] = 1
		a.append(temp)
	print(s)
	for i in range(n):
		temp = a[i]
		if d[temp] > 1:
			c = d[temp] - 1
			for j in range(4):
				ans = temp[:j] + str((int(temp[j]) + c) % 10) + temp[j + 1:]
				if not d.get(ans):
					print(ans)
					d[ans] = 1
					d[temp] -= 1
					break
			else:
				print('No answer')
		else:
			print(a[i])


for _ in range(int(input())):
	n = int(input())
	pins = []
	ans = 0
	for _ in range(n):
		pin = input()
		pins.append(pin)
	for (i, pin) in enumerate(pins):
		if pins.count(pin) == 1:
			continue
		for x in '0123456789':
			new_pin = x + pin[1:]
			if new_pin in pins:
				continue
			pins[i] = new_pin
			ans += 1
			break
	print(ans, *pins, sep='\n')


def solve(codes):
	unused = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	ex = []
	used_codes = set()
	acts = 0
	_codes = []
	for (i, j) in codes:
		first = int(i[0])
		if i not in used_codes:
			try:
				unused.remove(first)
			except:
				pass
			ex.append((i, j))
			used_codes.add(i)
		else:
			_codes.append((i, j))
	for (i, j) in _codes:
		first = int(i[0])
		if i not in used_codes:
			try:
				unused.remove(first)
			except:
				pass
			ex.append((i, j))
			used_codes.add(i)
		else:
			let = unused.pop()
			new_code = f'{let}{i[1:]}'
			ex.append((new_code, j))
			used_codes.add(new_code)
			acts += 1
	return (acts, ex)
n = int(input())
for i in range(n):
	cnt = int(input())
	codes = []
	for i in range(cnt):
		a = input()
		codes.append((a, i))
	(acts, cd) = solve(sorted(codes, key=lambda x: x[0]))
	print(acts)
	for code in sorted(cd, key=lambda x: x[1]):
		print(code[0])


import sys
input = sys.stdin.readline
import math
t = int(input())
for i1 in range(t):
	n = int(input())
	l = []
	rep = []
	last = []
	org = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(n):
		s = input()
		s = s.strip()
		if s in l:
			rep.append(s)
			l.append('')
		else:
			l.append(s)
			last.append(s[-1])
			if s[-1] in org:
				org.remove(s[-1])
	a1 = len(rep)
	curr = 0
	print(a1)
	j = 0
	for i in range(len(l)):
		if l[i] == '':
			s = rep[j]
			j += 1
			s = s[:-1] + org[curr]
			curr += 1
			l[i] = s
	for i in range(n):
		print(l[i])


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	p = '0123456789'
	ans = 0
	for i in range(n - 1):
		if arr[i] in arr[i + 1:]:
			ans += 1
			brr = []
			for j in range(n):
				brr.append(arr[j][0])
			for j in p:
				if j not in brr:
					arr[i] = j + arr[i][1:]
					break
	print(ans)
	for i in arr:
		print(i)


def solve():
	n = int(input())
	p = [input() for i in range(n)]
	p_dict = []
	c = 0
	for num in p:
		if num not in p_dict:
			p_dict.append(num)
		else:
			c += 1
			for i in range(4):
				b = False
				for j in range(9):
					s = list(num)
					s[i] = str((int(s[i]) + j + 1) % 10)
					s = ''.join(s)
					if s not in p and s not in p_dict:
						p_dict.append(s)
						b = True
						break
				if b:
					break
	return [c] + p_dict
t = int(input())
for case in range(t):
	for x in solve():
		print(x)


n = input()
n = int(n)
import collections
for _ in range(n):
	c = collections.Counter()
	k = int(input())
	ans = []
	for i in range(k):
		x = input()
		ans.append(x)
		c[x] += 1
	SUM = 0
	s = set('0123456789')
	for x in c:
		s.discard(x[0])
		SUM += c[x] - 1
	print(SUM)
	d = collections.defaultdict(set)
	for x in c:
		d[x].add(x)
		c[x] -= 1
		while c[x] != 0:
			c[x] -= 1
			y = s.pop() + x[1:]
			d[x].add(y)
	for (i, x) in enumerate(ans):
		print(d[x].pop())


t = int(input())
for i in range(t):
	n = int(input())
	p = []
	s = []
	d = {}
	for j in range(n):
		st = input()
		s.append(st)
		p.append(list(map(int, list(st))))
		if st in d.keys():
			d[st].append(j)
		else:
			d[st] = [j]
	poss = [i for i in range(10)]
	for j in range(n):
		poss[p[j][0]] = -1
	rest = [x for x in poss if x != -1]
	r_i = 0
	res = 0
	for k in d.keys():
		if len(d[k]) > 1:
			for r in d[k][1:]:
				p[r][0] = rest[r_i]
				r_i += 1
				res += 1
	print(res)
	for o in p:
		print(''.join(map(str, o)))


import sys, math
input = sys.stdin.readline

def inp():
	n = int(input())
	return n

def inlt():
	a = list(map(int, input().split()))
	return a

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	(a, b) = map(int, input().split())
	return (a, b)
t = 1
t = inp()
for tt in range(t):
	n = inp()
	a = []
	b = []
	for i in range(n):
		s = insr()
		a.append(s)
		b.append(s)
	c = 0
	for i in range(len(a)):
		qw = 0
		if a.count(a[i]) != 1:
			c = c + 1
			for j in range(4):
				for k in range(10):
					if int(a[i][j]) != k:
						a[i][j] = str(k)
					if a.count(a[i]) == 1:
						qw = 1
						break
					if qw == 1:
						break
				if qw == 1:
					break
	print(c)
	for i in range(len(a)):
		print(''.join(a[i]))


t = int(input())
for _ in range(t):
	n = int(input())
	list_cards = []
	dico_cards = {}
	for i in range(n):
		card = int(input())
		if card not in dico_cards:
			dico_cards[card] = 1
		else:
			dico_cards[card] += 1
		list_cards.append(card)
	k = 0
	for (_, j) in dico_cards.items():
		k += j - 1
	print(k)
	for i in range(n):
		if dico_cards[list_cards[i]] == 1:
			print(str(list_cards[i]).zfill(4))
		else:
			found = False
			for j in range(4):
				for c in range(10):
					new_pin = (list_cards[i] // (10 * 10 ** j) * 10 + c) * 10 ** j + list_cards[i] % 10 ** j
					if new_pin not in dico_cards:
						print(str(new_pin).zfill(4))
						dico_cards[new_pin] = 1
						dico_cards[list_cards[i]] -= 1
						found = True
					if found:
						break
				if found:
					break


q = int(input())
import math
for qq in range(q):
	q2 = int(input())
	dat = []
	c = []
	c.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
	c.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
	c.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
	c.append([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
	for qq2 in range(q2):
		s = input()
		dat.append(s)
		for i in range(4):
			c[i][int(s[i])] += 1
	count = 0
	for n in range(q2):
		isexist = False
		for nn in range(q2):
			if nn == n:
				continue
			if dat[n] == dat[nn]:
				isexist = True
		if isexist == False:
			continue
		count += 1
		s = dat[n]
		for i in range(10):
			if c[0][i] == 0:
				c[0][i] += 1
				c[0][int(dat[n][0])] -= 1
				dat[n] = str(i) + s[1] + s[2] + s[3]
	print(count)
	for i in range(len(dat)):
		print(dat[i])


q = int(input())
while q:
	q -= 1
	n = int(input())
	dic = {}
	s = []
	ct = 0
	for i in range(n):
		s.append(input())
		dic[s[i]] = dic.get(s[i], 0) + 1
	for i in range(n):
		if dic[s[i]] == 1:
			continue
		else:
			ct += 1
			s1 = list(s[i])
			j = 0
			s0 = s[i]
			while dic.get(s0, 0) >= 1 and j < 40:
				j1 = j // 10
				j2 = j - j1 * 10
				s1[j1] = str(j2)
				s0 = ''.join(s1)
				j += 1
			dic[s[i]] -= 1
			s[i] = s0
			dic[s0] = dic.get(s0, 0) + 1
	print(ct)
	for i in range(n):
		print(s[i])
exit()


t = int(input())
while t != 0:
	n = int(input())
	list1 = list()
	for i in range(n):
		list1.append(input())
	count = 0
	for i in range(len(list1)):
		if list1[i] in list1[i + 1:]:
			j = 0
			count += 1
			while list1[i] in list1[:i] + list1[i + 1:]:
				list1[i] = list1[i][:3] + str(j)
				j += 1
	print(count)
	for i in range(len(list1)):
		print(list1[i])
	t -= 1


import sys
import os
from io import BytesIO, IOBase
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')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, lst):
	set1 = set()
	for i in lst:
		set1.add(tuple(i))
	print(n - len(set1))
	seen = []
	for i in lst:
		if i in seen:
			for j in range(0, 10):
				val = [j, i[1], i[2], i[3]]
				if val not in seen and val not in lst:
					seen.append(val)
					break
		else:
			seen.append(i)
	for i in seen:
		print('0' * (4 - len(str(i))), end='')
		for j in i:
			print(j, end='')
		print()
for _ in range(int(input())):
	n = int(input())
	lst = []
	for i in range(n):
		lst.append(list(map(int, list(input()))))
	solve(n, lst)


q = int(input())
stn = []
code_f = []
cnt = []

def check(a, b):
	for x in range(len(a)):
		if a[x] == a[b] and x != b:
			return x
for x in range(q):
	code = []
	t = int(input())
	stn.append(t)
	for j in range(t):
		code.append(input())
		code = list(map(int, code))
	code_f.append(code)
	count = 0
	for k in range(t):
		for j in range(t):
			if code_f[x][k] == code_f[x][j] and k != j:
				while check(code_f[x], j) is not None:
					if code_f[x][j] % 10 != 9:
						code_f[x][j] = code_f[x][j] + 1
					elif code_f[x][j] % 10 == 9:
						code_f[x][j] = code_f[x][j] - 9
				count = count + 1
	cnt.append(count)
for x in range(q):
	print(cnt[x])
	for j in range(stn[x]):
		if code_f[x][j] < 10:
			print('000' + str(code_f[x][j]))
		elif code_f[x][j] < 100:
			print('00' + str(code_f[x][j]))
		elif code_f[x][j] < 1000:
			print('0' + str(code_f[x][j]))
		else:
			print(code_f[x][j])


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	pin_codes = []
	total = 0
	for _ in range(n):
		n = str(input())
		pin_codes.append(n)
	total = len(pin_codes) - len(set(pin_codes))
	if total == 0:
		print(total)
		for pin in pin_codes:
			print(pin)
	else:
		print(total)
		set_pins = set(pin_codes)
		before_pins = set()
		for pin in pin_codes:
			if pin not in before_pins:
				print(pin)
				before_pins.add(pin)
			else:
				start = 0
				while pin in set_pins:
					pin = str(start) + pin[1:]
					start += 1
				set_pins.add(pin)
				before_pins.add(pin)
				print(pin)


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
for _ in range(int(input())):
	n = int(input())
	ans = 0
	arr = []
	for q in range(n):
		s = list(map(str, input()))
		arr.append(s)
	for i in range(n):
		done = False
		while arr.count(arr[i]) > 1:
			done = True
			arr[i][-1] = str(int(arr[i][-1]) + 1)
			if int(arr[i][-1]) == 10:
				arr[i][-1] = str(0)
		if done:
			ans += 1
	print(ans)
	for i in range(n):
		print(''.join(arr[i]))


T = int(input())
for t in range(T):
	b = [[] for x in range(10)]
	n = int(input())
	for i in range(n):
		a = [int(x) for x in list(input())]
		b[a[0]].append((a, i))
	c = 10 * [0]
	for i in range(10):
		b[i].sort()
		c[i] = len(b[i])
	ans = 0
	for i in range(10):
		for j in range(c[i] - 2, -1, -1):
			if b[i][j][0] == b[i][j + 1][0]:
				ind = c.index(0)
				b[i][j][0][0] = ind
				b[ind].append(b[i][j])
				c[ind] = 1
				ans += 1
				b[i].pop(j)
	print(ans)
	p = n * ['']
	for x in b:
		for xx in x:
			p[xx[1]] = ''.join([str(xxx) for xxx in xx[0]])
	for i in range(n):
		print(p[i])


for i in range(int(input())):
	n = int(input())
	d = []
	ans = 0
	for j in range(n):
		d.append(input())
	for m in range(n):
		j = d[m]
		arr = list(j)
		flag = True if d.count(j) > 1 else False
		o = 0
		while flag:
			for p in range(0, 9):
				temp = arr[:]
				temp[o] = str(p)
				q = ''.join(temp)
				if str(p) != arr[o] and q not in d:
					d[m] = q
					ans += 1
					flag = False
					break
			o += 1
	print(ans)
	for i in d:
		print(str(i).zfill(4))


x = int(input())
for i in range(x):
	y = []
	count = 0
	n = [0] * 10
	z = int(input())
	for j in range(z):
		m = int(input())
		n[m % 10] += 1
		y = y + [(m, j)]
	p = sorted(y)
	for j in range(len(y) - 1):
		if p[j][0] == p[j + 1][0]:
			count += 1
			for r in range(10):
				if n[r] == 0:
					n[r] += 1
					y[p[j + 1][1]] = p[j + 1][0] - p[j + 1][0] % 10 + r
					break
		else:
			y[p[j + 1][1]] = p[j + 1][0]
	y[p[0][1]] = p[0][0]
	print(count)
	for j in range(z):
		for q in range(4 - len(str(y[j]))):
			print('0', end='')
		print(y[j])


from collections import Counter
DIGS = '0123456789'
t = int(input())
for _ in range(t):
	n = int(input())
	P = [input() for _ in range(n)]
	print(sum((v - 1 for v in Counter(P).values())))
	for i in range(len(P)):
		if P[i] in P[:i]:
			for dig in DIGS:
				if dig + P[i][1:] not in P:
					P[i] = dig + P[i][1:]
					break
	for p in P:
		print(p)


def calc(pins):
	out_pins = list()
	changes = 0
	for pin in pins:
		t_pins = set(map(tuple, pins))
		t_pins = list(t_pins)
		t_pins = list(map(list, pins))
		t_pins.remove(pin)
		if pin not in out_pins:
			out_pins.append(pin)
		else:
			while pin in out_pins or pin in t_pins:
				pin[-1] = (pin[-1] + 1) % 10
			else:
				changes += 1
				out_pins.append(pin)
	return (changes, out_pins)
for _ in range(int(input())):
	n = int(input())
	pins = [list(map(int, list(input()))) for _ in range(n)]
	(changes, out) = calc(pins)
	print(changes)
	for pin in out:
		print(''.join(list(map(str, pin))))


T = int(input())
for t in range(T):
	N = int(input())
	pin = [input() for _ in range(N)]
	if len(set(pin)) == N:
		print(0)
		for i in range(N):
			print(pin[i])
	else:
		used = set()
		ans = []
		cnt = 0
		for i in range(N):
			p = pin[i]
			if p not in used:
				ans.append(p)
				used.add(p)
			else:
				f = False
				cnt += 1
				for j in range(4):
					now = int(p[j])
					for k in range(10):
						if k == now:
							continue
						x = p[0:j] + str(k) + p[j + 1:4]
						if x not in used and x not in pin:
							ans.append(x)
							used.add(x)
							f = True
							break
					if f:
						break
		print(cnt)
		for i in range(N):
			print(ans[i])


t = int(input())
for utr in range(t):
	n = int(input())
	ar = [0 for i in range(20000)]
	ans = []
	kol = 0
	pr = []
	for i in range(n):
		pr.append([])
		pr[-1].append(input())
		pr[-1].append(i)
		ar[int(pr[-1][0])] += 1
	pr.sort()
	for i in range(len(pr)):
		st = pr[i][0]
		ans.append([])
		ans[-1].append(pr[i][1])
		if ar[int(st)] == 1:
			ans[-1].append(st)
		else:
			tr = 0
			tr = int(st) // 10 * 10
			anr = 0
			ar[int(pr[i][0])] -= 1
			for j in range(tr, tr + 10):
				if ar[j] == 0:
					ar[j] = 1
					anr = j
					break
			kol += 1
			if anr < 1000:
				anr = (4 - len(str(anr))) * '0' + str(anr)
			ans[-1].append(anr)
	print(kol)
	ans.sort()
	for i in range(len(ans)):
		print(ans[i][1])


for _ in range(int(input())):
	n = int(input())
	l = []
	d = {}
	e = {}
	z = set()
	for q in range(n):
		s = list(input())
		p = []
		for i in s:
			p.append(int(i))
		x = tuple(p)
		if x in d:
			d[x] += 1
			e[x].append(q)
		else:
			d[x] = 1
			e[x] = [q]
		z.add(x)
	ans = 0
	for i in d:
		ans = ans + (d[i] - 1)
	o = [(0, 0, 0, 0)] * n
	for i in d:
		if d[i] > 1:
			o[e[i].pop()] = i
			cnt = 0
			for j in range(d[i] - 1):
				p = []
				for k in range(3):
					p.append(i[k])
				f = 0
				while f == 0:
					p.append(cnt)
					if tuple(p) in z:
						p.pop()
						cnt += 1
					else:
						f = 1
						z.add(tuple(p))
						o[e[i].pop()] = tuple(p)
		else:
			o[e[i].pop()] = i
	print(ans)
	for i in o:
		s = []
		for k in i:
			s.append(str(k))
		print(''.join(s))


def find_new_pin_code(pin_code, free_digits):
	first_digit = free_digits[0].pop()
	res = str(first_digit) + pin_code[1:]
	return res
T = int(input())
for t in range(T):
	n = int(input())
	free_digits = [set((i for i in range(10))) for i in range(4)]
	pin_codes = []
	for i in range(n):
		pin_code = input()
		pin_codes.append(pin_code)
		for (i, digit) in enumerate(pin_code):
			free_digits[i].discard(int(digit))
	d = {}
	for pin_code in pin_codes:
		if pin_code in d:
			d[pin_code] += 1
		else:
			d[pin_code] = 1
	res = {}
	res_count = 0
	for (pin_code, count) in d.items():
		res[pin_code] = [pin_code]
		if count > 1:
			for j in range(count - 1):
				res_count += 1
				new_pin_code = find_new_pin_code(pin_code, free_digits)
				res[pin_code].append(new_pin_code)
	print(res_count)
	for pin_code in pin_codes:
		available_pin_codes = res[pin_code]
		next_pin_code = available_pin_codes.pop()
		print(next_pin_code)


import sys

def solve(n, codes):
	seen = set()
	to_change = []
	res = [None] * n
	for (idx, code) in enumerate(codes):
		if code in seen:
			to_change.append((idx, [int(d) for d in code]))
		else:
			res[idx] = code
		seen.add(code)
	changes = len(to_change)
	for (idx, code_lst) in to_change:
		origin = code_lst[0]
		for d in range(1, 11):
			code_lst[0] = (origin + d) % 10
			scode = ''.join(map(str, code_lst))
			if not scode in seen:
				seen.add(scode)
				res[idx] = scode
				break
	return (changes, res)
t = int(input())
for _ in range(t):
	n = int(input())
	codes = []
	for _ in range(n):
		codes.append(input().rstrip())
	(changes, new_codes) = solve(n, codes)
	print(changes)
	for code in new_codes:
		print(code)


for _ in range(int(input())):
	arr = []
	n = int(input())
	for t in range(n):
		pins = input()
		arr.append(pins)
	c = 0
	for i in range(n):
		if arr[i] in arr[i + 1:]:
			c += 1
			k = 0
			while arr[i] in arr[:i] + arr[i + 1:]:
				arr[i] = arr[i][:3] + str(k)
				k += 1
	print(c)
	for j in range(n):
		print(arr[j])


from collections import Counter
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	p = []
	for _ in range(n):
		p.append(input())
	cp = Counter(p)
	s = set(map(int, cp.keys()))
	print(n - len(cp))
	ans = []
	for pp in p:
		if cp[pp] == 1:
			ans.append(pp)
			continue
		inti = int(pp)
		i = list(map(int, list(pp)))
		for d in range(4):
			for k in range(10):
				tmp = inti + (k - i[d]) * 10 ** (3 - d)
				if tmp not in s:
					s.add(tmp)
					ans.append(str(tmp).zfill(4))
					cp[pp] -= 1
					break
			else:
				continue
			break
		else:
			assert False
	for i in ans:
		print(i)


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def solve():
	n = int(input())
	cards = [int(input()) for _ in range(n)]
	C = Counter(cards)
	S = set(cards)
	change = 0
	ans = []
	for c in cards:
		if C[c] == 1:
			ans.append(c)
			continue
		else:
			C[c] -= 1
			c = c // 10 * 10
			for i in range(10):
				if c + i not in S:
					ans.append(c + i)
					S.add(c + i)
					change += 1
					break
	print(change)
	print('\n'.join(['0' * (4 - len(str(v))) + str(v) for v in ans]))
N = int(input())
for _ in range(N):
	solve()


t = int(input())
for j in range(t):
	pinCodes = []
	ansList = []
	ans = 0
	n = int(input())
	for i in range(n):
		pinCodes.append(input())
	for k in range(n):
		currentCode = pinCodes[k]
		count_ = pinCodes.count(currentCode)
		a = 0
		while count_ > 1:
			currentCode = list(currentCode)
			currentCode[-1] = str(a)
			currentCode = ''.join(currentCode)
			pinCodes[k] = currentCode
			count_ = pinCodes.count(currentCode)
			a += 1
		if a > 0:
			ans += 1
		ansList.append(currentCode)
	print(ans)
	print('\n'.join(pinCodes))


from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		val = input()
		l.append(val)
	output = ['' for j in range(n)]
	for j in range(n):
		if l[j] not in output:
			output[j] = l[j]
	total = 0
	for j in range(n):
		val = l[j]
		index = 0
		flag = 0
		if output[j] == '':
			while True:
				if val in output:
					flag = 1
					val = val[0:3] + str(index)
					index += 1
				else:
					output[j] = val
					break
			if flag == 1:
				total += 1
	print(total)
	for j in output:
		print(j)


for _ in range(int(input())):
	n = int(input())
	inp = []
	first = set()
	match = []
	for i in range(n):
		x = input()
		first.add(x[0])
		if x in inp:
			match.append(i)
		inp.append(x)
	print(len(match))
	for i in range(n):
		if i not in match:
			print(inp[i])
		else:
			for j in range(0, n):
				l = str(j)
				if l not in first:
					first.add(l)
					print(l + inp[i][1:])
					break


for _ in range(int(input())):
	n = int(input())
	count = 0
	l = [list(map(int, input())) for _ in range(n)]
	for i in range(n):
		if l[i] in l[i + 1:]:
			count += 1
			while l[i] in l[i + 1:]:
				a = l[i][0]
				l[i][0] = (l[i][0] + count) % 10
				if l[i] in l[:i]:
					l[i][0] = a
					l[i][1] = (l[i][1] + 1) % 10
	print(count)
	for key in l:
		print(*key, sep='')


import random
t = int(input())
for i in range(t):
	p = int(input())
	l = []
	for j in range(p):
		l.append(list(input()))
	n = [[], [], [], []]
	for i in l:
		if i[0] not in n[0]:
			n[0].append(i[0])
		if i[1] not in n[1]:
			n[1].append(i[1])
		if i[2] not in n[2]:
			n[2].append(i[2])
		if i[3] not in n[3]:
			n[3].append(i[3])
	c = 0
	for j in range(0, p):
		for k in range(j + 1, p):
			if l[j] == l[k]:
				for f in range(0, 4):
					if len(n[f]) != 10:
						x = random.randint(0, 9)
						while ascii(x) in n[f]:
							x = random.randint(0, 9)
						l[k][f] = ascii(x)
						n[f].append(ascii(x))
						c += 1
						break
	print(c)
	for j in l:
		for k in j:
			print(k, end='')
		print()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(input())
	s = set([])
	count = 0
	ans = []
	for i in a:
		if i not in s:
			ans.append(i)
			s.add(i)
		else:
			count += 1
			for x in '0123456789':
				if i[:-1] + x not in s and i[:-1] + x not in a:
					ans.append(i[:-1] + x)
					s.add(i[:-1] + x)
					break
	print(count)
	for i in ans:
		print(i)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

def main():
	for _ in range(ii()):
		n = ii()
		l = []
		s = []
		f = {}
		for i in range(n):
			x = si()
			l.append(list(x))
			s.append(x)
		for i in range(n):
			if int(s[i]) not in f:
				f[int(s[i])] = 1
			else:
				f[int(s[i])] += 1
		d = {}
		cnt = 0
		for i in range(n):
			if f[int(s[i])] > 1:
				ss = s[i]
				flag = 0
				for j in range(4):
					for k in range(0, 10):
						g = ss[:j] + str(k) + ss[j + 1:]
						if int(g) not in f:
							f[int(s[i])] -= 1
							s[i] = g
							f[int(s[i])] = 1
							flag = 1
							cnt += 1
							break
					if flag == 1:
						break
		print(cnt)
		for i in s:
			print(i)
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	pin = [input() for i in range(n)]
	d = defaultdict(list)
	for i in range(len(pin)):
		d[pin[i]].append(i)
	updated_pin = defaultdict(list)
	new_pin = set()
	changes = 0
	for k in d:
		updated_pin[k].append(k)
		first_digit = k[0]
		duplicate_pins = len(d[k]) - 1
		for i in range(10):
			if not duplicate_pins:
				break
			p = str(i) + k[1:]
			if p not in d and p not in new_pin:
				updated_pin[k].append(p)
				new_pin.add(p)
				changes += 1
				duplicate_pins -= 1
	print(changes)
	list_of_updated_pins = []
	for p in pin:
		list_of_updated_pins.append(updated_pin[p].pop())
	for p in list_of_updated_pins:
		print(p)


for _ in range(int(input())):
	n = int(input())
	a = [[int(x) for x in input()] for _ in range(n)]
	(r1, r2, r3, r4) = [len(set([x[i] for x in a])) for i in range(4)]
	c = 0
	for i in range(n):
		for j in range(n):
			if i != j:
				if a[i] == a[j]:
					for t in range(10):
						if t not in [x[3] for x in a]:
							a[i][3] = t
							c += 1
							break
	print(c)
	for pin in a:
		print(''.join((str(x) for x in pin)))


def parse_one_pin(pin, set_of_pins):
	for i in range(1, 5):
		list_of_indices = indices_to_change(i)
		for indices in list_of_indices:
			new_pin = check_digits_change(pin, set_of_pins, indices)
			if new_pin is not None:
				return (new_pin, indices)

def parse_test_set(list_of_pins):
	dict_of_pins = {}
	new_list_of_pins = []
	for pin in list_of_pins:
		dict_of_pins[pin] = dict_of_pins[pin] + 1 if pin in dict_of_pins.keys() else 1
		new_list_of_pins.append(pin)
	total_changes = 0
	for (idx, pin) in enumerate(list_of_pins):
		current_set_of_pins = set(new_list_of_pins)
		if dict_of_pins[pin] > 1:
			(new_pin, indices) = parse_one_pin(pin, current_set_of_pins)
			total_changes += len(indices)
			new_list_of_pins[idx] = new_pin
			dict_of_pins[pin] -= 1
	print_res(new_list_of_pins, total_changes)

def indices_to_change(digit_to_modify):
	if digit_to_modify == 1:
		indices_to_modify = [[0], [1], [2], [3]]
	if digit_to_modify == 2:
		indices_to_modify = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
	if digit_to_modify == 3:
		indices_to_modify = [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
	if digit_to_modify == 4:
		indices_to_modify = [(1, 2, 3, 4)]
	return indices_to_modify

def check_digits_change(pin, pins_to_avoid, indices):
	new_pin = [int(x) for x in pin]
	for f in range(0, 10 ** len(indices)):
		digits_of_f = int_to_pin(f)
		for (i, index) in enumerate(indices):
			new_pin[index] = digits_of_f[3 - i]
			new_pin_str = ''.join((str(i) for i in new_pin))
			if new_pin_str not in pins_to_avoid:
				return ''.join((str(i) for i in new_pin))
	return None

def int_to_pin(number):
	list_of_digits = [int(d) for d in str(number)]
	while len(list_of_digits) < 4:
		list_of_digits = [0] + list_of_digits
	return list_of_digits

def print_res(result, total_changes):
	print(total_changes)
	for x in result:
		print(x)
t = int(input())
ls = []
ns = []
for _ in range(t):
	local_n = int(input())
	ns.append(local_n)
	local_list_of_cards = []
	for _ in range(local_n):
		local_list_of_cards.append(input())
	ls.append(local_list_of_cards)
for (i, x) in enumerate(ls):
	parse_test_set(x)


t = int(input())

def change(p, dct):
	if dct[p] == 1:
		return [p, 0]
	for j in range(4):
		for i in range(10):
			nw = list(p[:])
			nw[j] = str(i)
			nw = ''.join(nw)
			if nw not in dct:
				return [nw, 1]
for _ in range(t):
	n = int(input())
	l = {}
	pins = []
	for i in range(n):
		s = input()
		pins.append(s)
		if s in l:
			l[s] += 1
		else:
			l[s] = 1
	res = []
	cnt = 0
	for p in pins:
		(c, d) = change(p, l)
		cnt += d
		l[p] -= 1
		if l[p] == 0:
			del l[p]
		if c not in l:
			l[c] = 1
		else:
			l[c] += 1
		res.append(c)
	print(cnt)
	for i in res:
		print(i)


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	n = ii()
	cards = []
	for _ in range(n):
		cards.append(input())
	sc = set(cards)
	lsc = len(sc)
	if lsc == n:
		print(0)
		print(wr(cards))
	else:
		for i in range(n):
			j = 0
			while cards.count(cards[i]) > 1:
				cards[i] = cards[i][:3] + str(j)
				j += 1
		print(n - lsc)
		print(wr(cards))


t = int(input())
digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
for tc in range(t):
	n = int(input())
	pins = []
	k = 0
	for i in range(n):
		pins.append(input())
	for i in range(n):
		pin = pins[i]
		if pins.count(pin) > 1:
			k += 1
			for d in digits:
				trying = pin[:3] + d
				if trying not in pins:
					pins[i] = trying
					break
	print(k)
	for pin in pins:
		print(pin)


import sys, itertools, math, collections, random

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
for _ in range(ii()):
	P = []
	F = list(range(10))
	for _ in range(ii()):
		p = [int(i) for i in istr()]
		P.append(p)
		if p[0] in F:
			F.remove(p[0])
	ans = 0
	T = []
	for p in P:
		if P.count(p) > 1 and p not in T:
			p[0] = F.pop()
			ans += 1
		T.append(p)
	print(ans)
	for p in P:
		print(''.join((str(s) for s in p)))


from collections import defaultdict
t = int(input())
for _ in range(t):
	Dict = defaultdict(int)
	n = int(input())
	ans = []
	count = 0
	lis = []
	for i in range(n):
		s = input()
		Dict[s] += 1
		lis.append(s)
	for i in range(n):
		s1 = lis[i]
		if Dict[s1] == 1:
			ans.append(s1)
		else:
			for e in range(10):
				s2 = s1[:-1] + str(e)
				if Dict[s2] == 0:
					count += 1
					ans.append(s2)
					Dict[s2] += 1
					break
			Dict[s1] -= 1
	print(count)
	for i in range(len(ans)):
		print(ans[i])


t = int(input())
for i in range(t):
	n = int(input())
	PINS = []
	for j in range(n):
		PINS.append([input(), j])
	PINS.sort()
	a = [0] * 10
	for (pin, ind) in PINS:
		a[int(pin[3])] = 1
	sums = 0
	for j in range(len(PINS) - 1):
		for k in range(j + 1, len(PINS)):
			(pin1, ind) = PINS[j]
			(pin2, ind) = PINS[k]
			if pin1 == pin2:
				for l in range(len(a)):
					if a[l] == 0:
						a[l] += 1
						sums += 1
						PINS[k][0] = pin2[:3] + chr(48 + l)
						break
	PINS.sort(key=lambda x: x[1])
	print(sums)
	for (pin, ind) in PINS:
		print(pin)


for t in range(0, int(input())):
	m = int(input())
	s = []
	remaining = list(map(str, range(0, 10)))
	for i in range(0, m):
		temp = list(input())
		s.append((temp, i))
		if temp[3] in remaining:
			remaining.remove(temp[3])
	s.sort()
	nbr_of_changes = 0
	answers = []
	i = 1
	while i < len(s):
		if s[i][0] == s[i - 1][0]:
			s[i][0][3] = remaining[-1]
			remaining.pop()
			nbr_of_changes += 1
			answers.append(s.pop(i))
			i -= 1
		i += 1
	s.extend(answers)
	s.sort(key=lambda x: x[1])
	print(nbr_of_changes)
	for i in s:
		print(''.join(i[0]))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = []
	ans = 0
	for i in range(n):
		a += (input().rstrip('\n'),)
	for i in range(n):
		x = a[i]
		a[i] = 'x'
		if x in a:
			d = 0
			ans += 1
			while x in a:
				x = str(d) + x[1:]
				d += 1
		a[i] = x
	print(ans)
	for i in a:
		print(i)


import sys
sys.setrecursionlimit(10 ** 5)

def I():
	return sys.stdin.readline()

def SI():
	return sys.stdin.readline().split()

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
from collections import Counter
for _ in range(II()):
	n = II()
	codes = []
	for _ in range(n):
		codes.append(input())
	cnts = Counter(codes)
	ans = 0
	out = []
	for i in range(n):
		if cnts[codes[i]] == 1:
			out.append(codes[i])
		else:
			curr_code = codes[i]
			temp = list(curr_code)
			found = False
			for i in range(4):
				for j in range(10):
					temp[i] = str(j)
					if ''.join(temp) in cnts.keys():
						temp = list(curr_code)
					else:
						found = True
						cnts[''.join(temp)] = 1
						out.append(''.join(temp))
						ans += 1
						cnts[curr_code] -= 1
						break
				if found == True:
					break
	print(ans)
	for i in range(n):
		print(out[i])


t = int(input())
for _ in range(t):
	n = int(input())
	d = []
	m = dict()
	c = 0
	for ni in range(n):
		g = [int(x) for x in input().strip()]
		d.append(g)
		tg = tuple(g)
		if tg not in m:
			m[tg] = 0
		m[tg] += 1
	for ii in range(len(d)):
		tog = tuple(d[ii])
		if m[tog] > 1:
			for i in range(9):
				d[ii][3] = (d[ii][3] + 1) % 10
				tg = tuple(d[ii])
				if tg not in m:
					m[tog] -= 1
					m[tg] = 1
					c += 1
					break
	print(c)
	for g in d:
		print(*g, sep='')


def solve(n, cards):
	if len(set(cards)) == n:
		return (0, cards)
	digits = [set() for _ in range(4)]
	for card in cards:
		for (i, c) in enumerate(card):
			digits[i].add(c)
	ind = 0
	best = len(digits[0])
	for (i, d) in enumerate(digits):
		if len(d) < best:
			best = len(d)
			ind = i
	unused = set(map(str, range(10))) - digits[ind]
	it = iter(unused)
	seen = set()
	ans = []
	count = 0
	for card in cards:
		if card in seen:
			card2 = list(card)
			card2[ind] = next(it)
			card2 = ''.join(card2)
			ans.append(card2)
			seen.add(card2)
			count += 1
		else:
			ans.append(card)
			seen.add(card)
	return (count, ans)
for _ in range(int(input())):
	n = int(input())
	cards = [input() for _ in range(n)]
	(k, ans) = solve(n, cards)
	print(k)
	for a in ans:
		print(a)


import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
	n = int(input())
	LIST = [input().strip() for i in range(n)]
	SET = set()
	ANS = 0
	CHANGE = set()
	for i in range(n):
		if LIST[i] in SET:
			ANS += 1
			CHANGE.add(i)
		else:
			SET.add(LIST[i])
	ALIST = []
	for i in range(n):
		if i in CHANGE:
			flag = 0
			now = LIST[i]
			for j in range(4):
				for k in range(10):
					x = now[:j] + str(k) + now[j + 1:]
					if x in SET:
						continue
					else:
						ALIST.append(x)
						SET.add(x)
						flag = 1
						break
				if flag:
					break
		else:
			ALIST.append(LIST[i])
	print(ANS)
	print('\n'.join(ALIST))


T = int(input())
write = ''
for t in range(T):
	n = int(input())
	pins = dict()
	cards = []
	types = []
	for i in range(n):
		text = input()
		new = list(map(int, list(text)))
		cards.append(text)
		if new not in types:
			types.append(new)
		if pins.get(text):
			pins[text] += 1
		else:
			pins[text] = 1
	k = 0
	for pin in pins:
		if pins[pin] > 1:
			k += pins[pin] - 1
	write += str(k) + '\n'
	for i in range(len(cards)):
		card = cards[i]
		if pins[card] > 1:
			old = card
			card = list(map(int, list(card)))
			pos = -1
			while card in types:
				pos += 1
				for ii in range(10):
					card[pos] = ii
					if card not in types:
						break
			types.append(card)
			pins[old] -= 1
			new = ''.join(list(map(str, card)))
			cards[i] = new
			pins[new] = 1
			types.append(card)
	for card in cards:
		write += card + '\n'
print(write)


for _ in range(int(input())):
	l = []
	for _ in range(int(input())):
		l.append(int(input()))
	count = 0
	kurcic = set()
	for kita in l:
		kurcic.add(kita % 10)
	for i in range(len(l)):
		for j in range(len(l)):
			if i == j:
				continue
			if l[i] == l[j]:
				l[i] = l[i] // 10
				l[i] = l[i] * 10
				for picic in range(0, 10):
					if picic not in kurcic:
						l[i] = l[i] + picic
						kurcic.add(picic)
						break
				count += 1
				break
	print(count)
	for ele in l:
		print(f'{ele:04d}')


from sys import stdin, stdout
import math

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(input()))
	ans = 0
	used = [0] * n
	for i in range(n):
		if used[i]:
			continue
		for j in range(i + 1, n):
			if l[i] == l[j]:
				ans += 1
				used[j] = 1
				for k in range(4):
					for c in range(ord('0'), ord('9') + 1):
						temp = l[j].copy()
						temp[k] = chr(c)
						if l.count(temp) == 0:
							l[j] = temp.copy()
							break
					if l[i] != l[j]:
						break
	print(ans)
	for i in range(n):
		print(''.join(l[i]))
test = 1
test = int(input())
for __ in range(test):
	solve()


for _ in range(int(input())):
	n = int(input())
	pins = [list(map(int, input())) for _ in range(n)]
	changes = 0
	for i in range(n):
		change = 0
		while pins[i] in pins[:i] + pins[i + 1:]:
			change = 1
			pins[i][0] = (pins[i][0] + 1) % 10
		changes += change
	print(changes)
	for pin in pins:
		print(*pin, sep='')


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	c = {}
	ans = 0
	for i in range(n):
		a.append(input())
		c[a[i]] = 0
	for i in range(n):
		c[a[i]] += 1
	for i in range(n):
		if c[a[i]] > 1:
			f = 0
			while c[a[i]] > 1:
				if c.get(a[i][:3] + str(f)) == None:
					c[a[i]] -= 1
					a[i] = a[i][:3] + str(f)
					c[a[i]] = 1
					ans += 1
				f += 1
	print(ans)
	for i in range(n):
		print(a[i])


tests = int(input())
for _ in range(tests):
	n = int(input())
	s = set()
	p = [0] * n
	for i in range(n):
		p[i] = input()
		s.add(p[i])
	print(n - len(s))
	s1 = set()
	for i in range(n):
		if p[i] not in s1:
			s1.add(p[i])
		else:
			pin = p[i][1:]
			for u in range(0, 10):
				if str(u) + pin not in s1 and str(u) + pin not in s:
					s1.add(str(u) + pin)
					p[i] = str(u) + pin
					break
	for i in p:
		print(i)


t = {}
ti = eval(input())
stra = []
ans = []
while ti:
	t.clear()
	stra.clear()
	ans.clear()
	ti -= 1
	n = eval(input())
	ni = n
	while n:
		n -= 1
		strs = input()
		stra.append(strs)
		if not strs in t:
			t[strs] = 1
		else:
			t[strs] += 1
	tot = 0
	for i in range(0, ni):
		if t[stra[i]] == 1:
			ans.append(stra[i])
		else:
			flag = False
			t[stra[i]] -= 1
			for j in range(0, len(stra[i])):
				k = stra[i][j]
				for z in range(0, 10):
					ki = stra[i][:j] + str(z) + stra[i][j + 1:]
					stra[i] = ki
					if not stra[i] in t:
						ans.append(stra[i])
						tot += 1
						t[stra[i]] = 1
						flag = True
						break
				if flag:
					break
	print(tot)
	for i in ans:
		print(i)


t = int(input())
for i in range(t):
	r = int(input())
	l = []
	a = [0] * 10
	b = [0] * 10
	c = [0] * 10
	d = [0] * 10
	for j in range(r):
		st = str(input())
		l.append(st)
	se = set(l)
	if len(se) == r:
		print(0)
		for k in range(r):
			print(l[k])
	else:
		cc = 0
		r4 = set()
		for rt in range(len(l)):
			a[int(l[rt][0])] += 1
			b[int(l[rt][1])] += 1
			c[int(l[rt][2])] += 1
			d[int(l[rt][3])] += 1
			we = len(r4)
			r4.add(l[rt])
			if we + 1 == len(r4):
				continue
			else:
				copyrt = l[rt]
				cc = cc + 1
				elist = []
				for y in range(4):
					elist.append(int(l[rt][y]))
				c[int(l[rt][2])] -= 1
				done = 0
				for ui in range(len(c)):
					if c[ui] == 0:
						elist[2] = ui
						done = 1
						c[ui] += 1
						break
				for i in range(len(elist)):
					elist[i] = str(elist[i])
				strtest = ''.join(elist)
				ccstrtes = 0
				l[rt] = strtest
				for j in l:
					if j == strtest:
						ccstrtes += 1
				if ccstrtes > 1:
					c[int(l[rt][2])] -= 1
					elist[2] = copyrt[2]
					for ui in range(len(b)):
						if c[ui] == 0:
							elist[1] = ui
							done = 1
							b[ui] += 1
							break
					for i in range(len(elist)):
						elist[i] = str(elist[i])
					strtest = ''.join(elist)
				l[rt] = strtest
				r4.add(l[rt])
		print(cc)
		for k in range(r):
			print(l[k])