using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CF
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().run();
        }

        int g = 0;
        char getnext()
        {
            if (g == 10)
            {
                g = 0;
            }
            return (char)('0' + g++);
        }
        void run()
        {
            int t = ReadInt()[0];
            while(t != 0)
            {
                int n = ReadInt()[0];

                List<string> l = new List<string>();
                for (int i = 0; i < n; ++i)
                {
                    string tmp = Console.ReadLine();
                    l.Add(tmp);
                }

                int count = 0;
                HashSet<string> hs = new HashSet<string>();
                //HashSet<string> add = new HashSet<string>();

                List<string> res = new List<string>();
                foreach(string s in l)
                {
                    if (hs.Contains(s))
                    {
                        count++;
                        StringBuilder sb = new StringBuilder(s);
                        while(hs.Contains(sb.ToString()))
                        {
                            sb[0] = getnext();
                        }
                        hs.Add(sb.ToString());
                        res.Add(sb.ToString());
                    }
                    else
                    {
                        hs.Add(s);
                        res.Add(s);
                    }
                }

                Console.WriteLine(count);
                foreach(string s in res)
                {
                    Console.WriteLine(s);
                }

                t--;
            }
        }

        int[] ReadInt()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        long[] ReadLong()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CF
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().run();
        }

        int g = 0;
        char getnext()
        {
            if (g == 10)
            {
                g = 0;
            }
            return (char)('0' + g++);
        }
        void run()
        {
            int t = ReadInt()[0];
            while(t != 0)
            {
                int n = ReadInt()[0];

                List<string> l = new List<string>();
                for (int i = 0; i < n; ++i)
                {
                    string tmp = Console.ReadLine();
                    l.Add(tmp);
                }

                int count = 0;
                HashSet<string> hs = new HashSet<string>();

                List<string> res = new List<string>();
                HashSet<int> change = new HashSet<int>();
                for (int i = 0; i < l.Count; ++i)
                {
                    if (hs.Contains(l[i]))
                    {
                        count++;
                        change.Add(i);
                    }
                    else
                    {
                        hs.Add(l[i]);
                    }
                }

                for (int i = 0; i < l.Count; ++i)
                {
                    if (change.Contains(i))
                    {
                        StringBuilder sb = new StringBuilder(l[i]);
                        while (hs.Contains(sb.ToString()))
                        {
                            sb[0] = getnext();
                        }
                        res.Add(sb.ToString());
                    }
                    else
                    {
                        res.Add(l[i]);
                    }
                }

                Console.WriteLine(count);
                foreach(string s in res)
                {
                    Console.WriteLine(s);
                }

                t--;
            }
        }

        int[] ReadInt()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        long[] ReadLong()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CF
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().run();
        }

        int g = 0;
        char getnext()
        {
            if (g == 10)
            {
                g = 0;
            }
            return (char)('0' + g++);
        }
        void run()
        {
            int t = ReadInt()[0];
            while(t != 0)
            {
                int n = ReadInt()[0];

                List<string> l = new List<string>();
                for (int i = 0; i < n; ++i)
                {
                    string tmp = Console.ReadLine();
                    l.Add(tmp);
                }

                int count = 0;
                HashSet<string> hs = new HashSet<string>();
                //HashSet<string> add = new HashSet<string>();

                List<string> res = new List<string>();
                char c = '0';
                foreach(string s in l)
                {
                    if (hs.Contains(s))
                    {
                        count++;
                        StringBuilder sb = new StringBuilder(s);
                        while(hs.Contains(sb.ToString()))
                        {
                            sb[0] = getnext();
                        }
                        res.Add(sb.ToString());
                    }
                    else
                    {
                        hs.Add(s);
                        res.Add(s);
                    }
                }

                Console.WriteLine(count);
                foreach(string s in res)
                {
                    Console.WriteLine(s);
                }

                t--;
            }
        }

        int[] ReadInt()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        long[] ReadLong()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace cf603
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf603B();
        }

        /*
        According to the description we can have no more than 10 pin-codes.
        Which means that if we use all ten codes usin different (for example) last digit
        0
        1
        ..
        9
        it means that all codes are unique.
        If we have 2 equal codes and the rest 8 are different. it means that we have something like this:
        1
        1
        2
        3
        ..
        9
        We have 9 out of 10 digits that are different. And we have 1 possibility to make all 10 codes different
        by replacing the digit that was not used. In this case it is 0.
        0
        1
        2
        3
        ..
        9
        How to do this. We just use aray of used digits.
         */
        public static void solve_cf603B()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int tt = 0; tt < t; tt++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                List<string> pins = new List<string>();
                Dictionary<string, int> used = new Dictionary<string, int>();
                for (int i = 0; i < n; i++)
                {
                    string s = Console.ReadLine();
                    pins.Add(s);
                    if (used.ContainsKey(s))
                    {
                        used[s]++;
                    }
                    else
                    {
                        used.Add(s, 1);
                    }
                }

                int cnt = 0;
                List<string> res = new List<string>();
                for (int i = 0; i < n; i++)
                {
                    if (used.ContainsKey(pins[i]) && used[pins[i]] > 1)
                    {
                        for (int j = 48; j <= 57; j++)
                        {
                            char[] s = pins[i].ToCharArray();
                            s[0] = (char)j;
                            string newS = new String(s);
                            if (!used.ContainsKey(newS))
                            {
                                used.Add(newS, 1);
                                used[pins[i]]--;
                                pins[i] = newS;
                                break;
                            }
                        }
                        cnt++;
                    }
                }

                Console.WriteLine(cnt);
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(pins[i]);
                }
            }
        }

        /*
        Editorial
        */
        public static void solve_cf603AEditorial()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int b = rgb[0];
                int g = rgb[1];
                int r = rgb[2];

                if (r <= g + b)
                {
                    Console.WriteLine((r + b + g) / 2);
                }
                else
                {
                    Console.WriteLine(b + g);
                }

            }
        }

        public static void solve_cf603Av2()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int r = rgb[0];
                int g = rgb[1];
                int b = rgb[2];

                int diff = Math.Min(g, b - g);
                int diff2 = Math.Max(0, r - diff);
                int r1 = diff2 == 1 ? 1 : diff2 / 2;
                diff = r1 > 0 ? diff : 0;
                int r2 = diff2 - r1 + diff;

                Console.WriteLine(r + Math.Min(g - r1, b - r2));
            }
        }

        /*
        Wrong solution
         */
        public static void solve_cf603A()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int r = rgb[0];
                int g = rgb[1];
                int b = rgb[2];

                int max1 = g + Math.Min(r, b - g);

                int max2 = 0;
                int max = 0;

                int r1 = Math.Min(1, r / 2 - (b - g));
                int r2 = r - r1;
                max = Math.Max(max, Math.Min(g - r1, b - r2));
                max2 += r + max;

                Console.WriteLine(Math.Max(max1, max2));
            }

        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace cf603
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf603B();
        }

        /*
        According to the description we can have no more than 10 pin-codes.
        Which means that if we use all ten codes usin different (for example) last digit
        0
        1
        ..
        9
        it means that all codes are unique.
        If we have 2 equal codes and the rest 8 are different. it means that we have something like this:
        1
        1
        2
        3
        ..
        9
        We have 9 out of 10 digits that are different. And we have 1 possibility to make all 10 codes different
        by replacing the digit that was not used. In this case it is 0.
        0
        1
        2
        3
        ..
        9
        How to do this. We just use aray of used digits.
         */
        public static void solve_cf603B()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int tt = 0; tt < t; tt++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                List<int[]> pins = new List<int[]>();
                Dictionary<int, int> used = new Dictionary<int, int>();
                for (int i = 0; i < n; i++)
                {
                    string s = Console.ReadLine();
                    int[] temp = new int[s.Length];
                    for (int j = 0; j < s.Length; j++)
                    {
                        temp[j] = s[j] - '0';
                    }
                    if (used.ContainsKey(temp[0]))
                    {
                        used[temp[0]]++;
                    }
                    else
                    {
                        used.Add(temp[0], 1);
                    }
                    pins.Add(temp);
                }

                int cnt = 0;
                for (int i = 0; i < n; i++)
                {
                    if (used.ContainsKey(pins[i][0]) && used[pins[i][0]] > 1)
                    {
                        for (int j = 0; j <= 9; j++)
                        {
                            if (!used.ContainsKey(j))
                            {
                                used[pins[i][0]]--;
                                pins[i][0] = j;
                                used.Add(j, 1);
                                break;
                            }
                        }
                        cnt++;
                    }
                }

                Console.WriteLine(cnt);
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < pins[i].Length; j++)
                    {
                        Console.Write("{0}", pins[i][j]);
                    }
                    Console.WriteLine();
                }
            }
        }

        /*
        Editorial
        */
        public static void solve_cf603AEditorial()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int b = rgb[0];
                int g = rgb[1];
                int r = rgb[2];

                if (r <= g + b)
                {
                    Console.WriteLine((r + b + g) / 2);
                }
                else
                {
                    Console.WriteLine(b + g);
                }

            }
        }

        public static void solve_cf603Av2()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int r = rgb[0];
                int g = rgb[1];
                int b = rgb[2];

                int diff = Math.Min(g, b - g);
                int diff2 = Math.Max(0, r - diff);
                int r1 = diff2 == 1 ? 1 : diff2 / 2;
                diff = r1 > 0 ? diff : 0;
                int r2 = diff2 - r1 + diff;

                Console.WriteLine(r + Math.Min(g - r1, b - r2));
            }
        }

        /*
        Wrong solution
         */
        public static void solve_cf603A()
        {
            int t = Convert.ToInt32(Console.ReadLine());

            for (int tt = 0; tt < t; tt++)
            {
                int[] rgb = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Array.Sort(rgb);
                int r = rgb[0];
                int g = rgb[1];
                int b = rgb[2];

                int max1 = g + Math.Min(r, b - g);

                int max2 = 0;
                int max = 0;

                int r1 = Math.Min(1, r / 2 - (b - g));
                int r2 = r - r1;
                max = Math.Max(max, Math.Min(g - r1, b - r2));
                max2 += r + max;

                Console.WriteLine(Math.Max(max1, max2));
            }

        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using static System.Numerics.BigInteger;
using static Program.IO.Scanner;

using Number = System.Int64;
#region IO
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}
	static public class Scanner {
		public static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
		public static int ri => sc.Integer();
		public static long rl => sc.Long();
		public static string rs => sc.Scan();
		public static double rd => sc.Double();
	}
	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}

}

#endregion

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}

	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		var t = new System.Threading.Thread(solver.Solve, 10000000);
		t.Start();
		t.Join();
		//*/
		//solver.Solve();
		Console.Out.Flush();
	}
}
#endregion

namespace Program {
	public class Solver {
		Random rnd = new Random(0);
		public void Solve() {
			var T = ri;
			for (int _ = 0; _ < T; _++) {
				var n = ri;
				var a = Enumerate(n, x => rs.ToCharArray());
				var cnt = 0;
				for (int i = 0; i < n; i++) {
					var ok = true;
					for (int j = 0; j < n; j++)
						if (i != j) ok &= a[i].AsString() != a[j].AsString();
					if (!ok) {
						cnt++;
						var po = new char[0];
						for (int k = 0; k < 4; k++)
							for (int v = 0; v < 10; v++) {
								var b = a[i].ToArray();
								b[k] = (char)('0' + v);
								var okok = true;
								for (int j = 0; j < n; j++)
									if (i != j) okok &= b.AsString() != a[j].AsString();
								if (okok) po = b;
							}
						a[i] = po;
					}
				}
				Console.WriteLine(cnt);
				foreach (var x in a)
					Console.WriteLine(x.AsString());
			}

		}

		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a;
		}
		static T[][] Enumerate<T>(int n, int m, Func<int, int, T> f) {
			return Enumerate(n, x => Enumerate(m, y => f(x, y)));
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}


using System;
using System.Linq;
using System.Text;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        var sb = new StringBuilder();
        for (int i = 0; i < t; i++)
        {
            int n = sc.NextInt();
            string[] p = new string[n];
            for (int j = 0; j < n; j++)
            {
                p[j] = sc.Next();
            }
            sb.AppendLine(Q(n, p));
        }

        Console.Write(sb);
    }

    string Q(int n, string[] p)
    {
        int cnt = 0;
        char[][] ans = new char[n][];

        for (int i = 0; i < n; i++)
        {
            bool flag = false;
            for (int j = 0; j < i; j++)
            {
                bool f = true;
                for (int k = 0; k < 4; k++)
                {
                    f &= p[i][k] == ans[j][k];
                }
                flag |= f;
            }
            ans[i] = p[i].ToCharArray();
            if (flag)
            {
                bool[] f = new bool[10];
                for (int j = 0; j < n; j++)
                {
                    if (i == j) continue;
                    if (j < i) f[ans[j][0] - '0'] = true;
                    if (j > i) f[p[j][0] - '0'] = true;
                }

                for (int k = 0; k < 10; k++)
                {
                    if (!f[k])
                    {
                        ans[i][0] = (char)(k + '0');
                        break;
                    }

                }
                cnt++;
            }
        }

        return $"{cnt}\n{string.Join("\n", ans.Select(ar => new string(ar)))}";
    }
    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            writer.WriteLine(valueToWrite.ToString("F8"));
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int t;
        int n;

        Dictionary<string, List<int>> cards = new Dictionary<string, List<int>>();

        string []newVal;

        public void Solve()
        {
            t = ioHelper.ReadNextInt();
            newVal = new string[12];

            while (t > 0)
            {
                n = ioHelper.ReadNextInt();
                int rez=0;
                int i;
                for(i=0;i<n;i++)
                {
                    var str = ioHelper.ReadNextToken();
                    newVal[i] = str;
                    if (!cards.ContainsKey(str))
                        cards.Add(str, new List<int>());

                    cards[str].Add(i);
                }
                var origCards = cards.Keys.ToArray();
                foreach (var origCard in origCards)
                {
                    var lst = cards[origCard];
                    var str = new StringBuilder(origCard);
                    rez += lst.Count - 1;
                    var delta = lst.Count - 1;
                    if (delta <= 0)
                        continue;
                    for (int dig = 3; dig >= 0; dig--)
                    {
                        for (var ch = '9'; ch >= '0'; ch--)
                        {
                            var tmp = str[dig];
                            str[dig] = ch;
                            var tri = str.ToString();
                            if (!cards.ContainsKey(tri))
                            {
                                cards.Add(tri,new List<int>());
                                newVal[lst[delta]] = tri;
                                delta--;
                                if (delta == 0)
                                    break;
                            }
                        }
                        if (delta == 0)
                            break;
                    }
                }
                ioHelper.WriteLine(rez.ToString());
                for (i = 0; i < n; i++)
                    ioHelper.WriteLine(newVal[i]);
                cards.Clear();
                t--;
            }
            ioHelper.WriteLine("");
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int T = int.Parse(Console.ReadLine());
		for(var t=0;t<T;t++){
			int N = int.Parse(Console.ReadLine());
			var dic = new Dictionary<int,int>();
			int[]A = new int[N];
			for(var i=0;i<N;i++){
				A[i] = int.Parse(Console.ReadLine());
				if(dic.ContainsKey(A[i])){
					dic[A[i]]++;
				} else {
					dic[A[i]] = 1;
				}
			}
			int ans = 0;
			foreach(var j in dic){
				if(j.Value >= 2){
					ans += j.Value - 1;
				}
			}
			Console.WriteLine(ans);
			for(var i=0;i<N;i++){
				int ct = 0;
				for(var j=0;j<N;j++){
					if(A[j]==A[i]){
						ct++;
					}
				}
				if(ct >= 2){
				    int at = A[i];
				    int ac = 1;
					while(true){
						A[i] += ac;
						while(true){
						if(A[i]/ac%10==0){
						    if(A[i]>=10000){
						        A[i] = at;
						        ac = -1;
						        A[i] += ac;
						    } else {
    							A[i] = at;
	    						ac *= 10;
		    					A[i] += ac;
						    }
						} else {
						    break;
						}
						}
						int ct2 = 0;
						for(var j=0;j<N;j++){
							if(A[j]==A[i]){
								ct2++;
							}
						}
						if(ct2 <= 1){
							break;
						}
					}
				}
				int a1 = A[i]/1000;
				int a2 = A[i]/100%10;
				int a3 = A[i]/10%10;
				int a4 = A[i]%10;
				Console.WriteLine(a1+""+a2+""+a3+""+a4);
			}
		}
	}
}


using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int T = int.Parse(Console.ReadLine());
		for(var t=0;t<T;t++){
			int N = int.Parse(Console.ReadLine());
			var dic = new Dictionary<int,int>();
			int[]A = new int[N];
			for(var i=0;i<N;i++){
				A[i] = int.Parse(Console.ReadLine());
				if(dic.ContainsKey(A[i])){
					dic[A[i]]++;
				} else {
					dic[A[i]] = 1;
				}
			}
			int ans = 0;
			foreach(var j in dic){
				if(j.Value >= 2){
					ans += j.Value - 1;
				}
			}
			Console.WriteLine(ans);
			for(var i=0;i<N;i++){
				int ct = 0;
				for(var j=0;j<N;j++){
					if(A[j]==A[i]){
						ct++;
					}
				}
				if(ct >= 2){
				    int at = A[i];
				    int ac = 1;
					while(true){
						A[i] += ac;
						if(A[i]/ac%10==0){
						    if(A[i]>=10000){
						        A[i] = at;
						        ac = -1;
						        A[i] += ac;
						    } else {
    							A[i] = at;
	    						ac *= 10;
		    					A[i] += ac;
						    }
						}
						int ct2 = 0;
						for(var j=0;j<N;j++){
							if(A[j]==A[i]){
								ct2++;
							}
						}
						if(ct2 <= 1){
							break;
						}
					}
				}
				int a1 = A[i]/1000;
				int a2 = A[i]/100%10;
				int a3 = A[i]/10%10;
				int a4 = A[i]%10;
				Console.WriteLine(a1+""+a2+""+a3+""+a4);
			}
		}
	}
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Codeforces
{
    class Solution
    {
        void Solve()
        {
            int t = NextInt();
            for (int i = 0; i < t; ++i) SolveTest();
        }

        private void SolveTest()
        {
            int n = NextInt();
            var pins = new char[n][];
            for (int i = 0; i < n; ++i)
            {
                pins[i] = NextToken().ToCharArray();
            }

            int changes = 0;

            for (int i = 1; i < n; ++i)
                for (int j = 0; j < i; ++j)
                    if (new string(pins[i]) == new string(pins[j]))
                    {
                        ++changes;

                        for (int d = 0; d < 10; ++d)
                        {
                            bool ok = true;
                            for (int k = 0; k < n; ++k)
                            {
                                if (pins[k][0] == d + '0')
                                {
                                    ok = false;
                                    break;
                                }
                            }
                            if (ok)
                            {
                                pins[i][0] = (char)(d + '0');
                                break;
                            }
                        }

                        break;
                    }

            Console.WriteLine(changes);
            for (int i = 0; i < n; ++i)
                Console.WriteLine(new string(pins[i]));
        }

        #region Local Setup

        int NextInt() { return inputReader.NextInt(); }

        int[] NextIntArray(int length) { return inputReader.NextIntArray(length); }

        long NextLong() { return inputReader.NextLong(); }

        long[] NextLongArray(int length) { return inputReader.NextLongArray(length); }

        double NextDouble() { return inputReader.NextDouble(); }

        double[] NextDoubleArray(int length) { return inputReader.NextDoubleArray(length); }

        string NextLine() { return inputReader.NextLine(); }

        string NextToken() { return inputReader.NextToken(); }

        void Start()
        {
#if CSGO
            var timer = new Stopwatch();
            timer.Start();
            inputReader = new InputReader("input.txt");
#else
            inputReader = new InputReader(Console.In);
#endif
            using (inputReader)
            {
                var solutionThread = new Thread(Solve, 32 * (1 << 20));
                solutionThread.Start();
                solutionThread.Join();
            }
#if CSGO
            timer.Stop();
            Console.WriteLine(string.Format("Finished in {0}", timer.ElapsedMilliseconds / 1000.0));
            Console.ReadLine();
#endif
        }

        static void Main()
        {
            new Solution().Start();
        }

        private InputReader inputReader;

        class InputReader : IDisposable
        {
            private const int BufferSize = 1 << 17;
            private readonly TextReader textReader;
            private readonly char[] buf;
            private int pos, len;

            public InputReader(TextReader textReader)
            {
                this.textReader = textReader;
                buf = new char[BufferSize];
            }

            public InputReader(string fileName) : this(new StreamReader(fileName, Encoding.Default)) { }

            public void Dispose()
            {
                if (textReader != null && textReader != Console.In)
                {
                    textReader.Close();
                }
            }

            public bool Eof
            {
                get
                {
                    if (pos < len) return false;
                    FillBuffer(false);
                    return pos >= len;
                }
            }

            private char NextChar()
            {
                if (pos < len) return buf[pos++];
                FillBuffer(true);
                return buf[pos++];
            }

            private char PeekChar()
            {
                if (pos < len) return buf[pos];
                FillBuffer(true);
                return buf[pos];
            }

            private void FillBuffer(bool throwOnEof)
            {
                len = textReader.Read(buf, 0, buf.Length);
                if (throwOnEof && Eof)
                {
                    throw new IOException("Can't read beyond the end of file");
                }
                pos = 0;
            }

            public int NextInt()
            {
                var neg = false;
                int res = 0;
                SkipWhitespaces();
                if (!Eof && PeekChar() == '-')
                {
                    neg = true;
                    pos++;
                }
                while (!Eof && !IsWhitespace(PeekChar()))
                {
                    var c = NextChar();
                    if (c < '0' || c > '9') throw new ArgumentException("Illegal character");
                    res = 10 * res + c - '0';
                }
                return neg ? -res : res;
            }

            public int[] NextIntArray(int n)
            {
                var res = new int[n];
                for (int i = 0; i < n; i++)
                {
                    res[i] = NextInt();
                }
                return res;
            }

            public long NextLong()
            {
                var neg = false;
                long res = 0;
                SkipWhitespaces();
                if (!Eof && PeekChar() == '-')
                {
                    neg = true;
                    pos++;
                }
                while (!Eof && !IsWhitespace(PeekChar()))
                {
                    var c = NextChar();
                    if (c < '0' || c > '9') throw new ArgumentException("Illegal character");
                    res = 10 * res + c - '0';
                }
                return neg ? -res : res;
            }

            public long[] NextLongArray(int n)
            {
                var res = new long[n];
                for (int i = 0; i < n; i++)
                {
                    res[i] = NextLong();
                }
                return res;
            }

            public string NextLine()
            {
                SkipUntilNextLine();
                if (Eof) return "";
                var builder = new StringBuilder();
                while (!Eof && !IsEndOfLine(PeekChar()))
                {
                    builder.Append(NextChar());
                }
                return builder.ToString();
            }

            public string NextToken()
            {
                SkipWhitespaces();
                var builder = new System.Text.StringBuilder();
                while (!Eof && !IsWhitespace(PeekChar()))
                {
                    builder.Append(NextChar());
                }
                return builder.ToString();
            }

            public double NextDouble()
            {
                SkipWhitespaces();
                var builder = new StringBuilder();
                while (!Eof && !IsWhitespace(PeekChar()))
                {
                    builder.Append(NextChar());
                }
                return double.Parse(builder.ToString(), CultureInfo.InvariantCulture);
            }

            public double[] NextDoubleArray(int n)
            {
                var res = new double[n];
                for (int i = 0; i < n; i++)
                {
                    res[i] = NextDouble();
                }
                return res;
            }

            private void SkipWhitespaces()
            {
                while (!Eof && IsWhitespace(PeekChar()))
                {
                    ++pos;
                }
            }

            private void SkipUntilNextLine()
            {
                while (!Eof && IsEndOfLine(PeekChar()))
                {
                    ++pos;
                }
            }

            private static bool IsWhitespace(char c)
            {
                return c == ' ' || c == '\t' || c == '\n' || c == '\r';
            }

            private static bool IsEndOfLine(char c)
            {
                return c == '\n' || c == '\r';
            }
        }

        #endregion
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
struct B : IComparable
{
    public int Pos { get; set; }
    public char[] S { get; set; }

    public int CompareTo(object obj)
    {
        var s = new string(S);
        var anotherS = new string(((B)obj).S);
        return s.CompareTo(anotherS);
    }
}
class A
{

    public static void Main(string[] args)
    {
        int t = int.Parse(Console.ReadLine()); ;
        while (t > 0)
        {
            int n = int.Parse(Console.ReadLine()); ;
            var list = new B[n];
            for(int i = 0; i < n; i++)
            {
                list[i] = new B() { Pos = i , S = Console.ReadLine().ToCharArray() };
            }
            Array.Sort(list);
            int changes = 0;
            var notAvailableDigit = list.Select(x => (int)x.S[0]).ToArray().Distinct().ToList();
            for (int i = 1; i < n; i++)
            {
                if (new string(list[i].S) == new string(list[i - 1].S))
                {
                    for (int d = 48; d <= 57; d++)
                    {
                        if (!notAvailableDigit.Contains(d))
                        {
                            changes++;
                            list[i-1].S[0] = (char)d;
                            notAvailableDigit.Add((char)d);
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(changes);
            foreach(var a in list.OrderBy(x => x.Pos))
            {
                Console.WriteLine(new string(a.S));
            }
            t--;
        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tree
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            while(t--!=0)
            {
                int n = int.Parse(Console.ReadLine());
                StringBuilder[] codes = new StringBuilder [n];
                for(int i = 0; i<n; i++)
                {
                    codes[i] = new StringBuilder(Console.ReadLine());
                }
                HashSet<string> UnicCodes = new HashSet<string>();
                for (int i = 0; i < n; i++)
                {
                    bool flag = true;
                    for (int j = 0; j < n; j++)
                    {
                        if (i != j && codes[i] == codes[j])
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                        UnicCodes.Add(codes[i].ToString());
                }
                HashSet<char> UnikSymbol = new HashSet<char>();
                for (int i = 0; i < n; i++)
                    UnikSymbol.Add(codes[i][0]);
                Stack<char> stack = new Stack<char>();
                foreach (char s in new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' })
                    if (!UnikSymbol.Contains(s))
                        stack.Push(s);
                int count = UnicCodes.Count;
                for (int i = 0; i < n; i++)
                {
                    if (UnicCodes.Contains(codes[i].ToString()))
                        UnicCodes.Remove(codes[i].ToString());
                    else
                    {
                        codes[i][0] = stack.Pop();
                    }
                }
                Console.WriteLine(n - count);
                for(int i = 0; i<n; i++)
                    Console.WriteLine(codes[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tree
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            while(t--!=0)
            {
                int n = int.Parse(Console.ReadLine());
                StringBuilder[] codes = new StringBuilder [n];
                for(int i = 0; i<n; i++)
                {
                    codes[i] = new StringBuilder(Console.ReadLine());
                }
                HashSet<char>[] Unik = new HashSet<char>[4];
                for (int i = 0; i < 4; i++)
                    Unik[i] = new HashSet<char>();
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < 4; j++)
                        Unik[j].Add(codes[i][j]);
                int index = 0;
                for (int i = 1; i < 4; i++)
                    if (Unik[i].Count > Unik[index].Count)
                        index = i;
                Dictionary<char, int> charCount = new Dictionary<char, int>();
                for(int i = 0; i<n; i++)
                {
                    if (charCount.Keys.Contains(codes[i][index]))
                        charCount[codes[i][index]]++;
                    else
                        charCount[codes[i][index]] = 1;
                }
                Stack<char> Unik2 = new Stack<char>();
                foreach (char s in new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' })
                    if (!Unik[index].Contains(s))
                        Unik2.Push(s);
                for(int i = 0; i<n; i++)
                {
                    if(charCount[codes[i][index]] != 1)
                    {
                        charCount[codes[i][index]]--;
                        codes[i][index] = Unik2.Pop();
                    }
                }
                Console.WriteLine(n - Unik[index].Count);
                for(int i = 0; i<n; i++)
                    Console.WriteLine(codes[i]);
            }
        }
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins.Sort());

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; i < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins.Sort());

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int i = 0; i < pins.Length; i++){
                Console.WriteLine(FormatToPin(pins[i]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; i < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    Console.WriteLine($"x:{x}");
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        Console.WriteLine($"y:{y}");
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input})...");
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            Console.WriteLine($"d:{d}");
            for(int i = 0; i < 10; i ++){
                Console.WriteLine($"i:{i}");
                if(i == GetDigit(input, d + 1))
                    continue;
                int attempt = ChangeDigit(input, d + 1, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    Console.WriteLine($"New input : {attempt}..."); //DELETETHIS
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        Console.WriteLine($"Getting digit {d} from {n}..");
        string str = n.ToString();
        Console.WriteLine($"It is {str[d - 1]}!");
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    Console.WriteLine($"x:{x}");
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        Console.WriteLine($"y:{y}");
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input})...");
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            Console.WriteLine($"d:{d}");
            for(int i = 0; i < 10; i ++){
                Console.WriteLine($"i:{i}");
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    Console.WriteLine($"New input : {attempt}..."); //DELETETHIS
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        Console.WriteLine($"Getting digit {d} from {n}..")
        string str = n.ToString();
        Console.WriteLine($"It is {str[d - 1]}!");
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        foreach(int[] x in p){
            Console.WriteLine(x.Length);
            foreach(int y in x){
                Console.WriteLine(y);
            }
        }

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    Console.WriteLine($"x:{x}");
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        Console.WriteLine($"y:{y}");
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input})...");
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    Console.WriteLine($"New input : {attempt}..."); //DELETETHIS
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins.Sort());

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input}, {(LogIntArray(arr))})...")
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    static string LogIntArray(int[] arr){
        string r = "";
        for(int i = 0; i < arr.Length; i ++){
            r += $"{(arr[i])}, ";
        }
        return r;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    Console.WriteLine($"x:{x}");
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        Console.WriteLine($"y:{y}");
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        Console.WriteLine($"GetDistinct({input})...");
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            Console.WriteLine($"d:{d}");
            for(int i = 0; i < 10; i ++){
                Console.WriteLine($"i:{i}");
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    Console.WriteLine($"New input : {attempt}..."); //DELETETHIS
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        Console.WriteLine($"Getting digit {d} from {n}..");
        string str = n.ToString();
        Console.WriteLine($"It is {str[d - 1]}!");
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t; i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //^^ DEFINITELY WORKS

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins);

            int changes = 0;

            while(!Distinct(pins)){
                for(int x = 0; x < pins.Length; x ++){
                    int current = pins[x];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int y = x + 1; y < pins.Length; y ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[y]){
                            changes++;
                            pins[y] = GetDistinct(pins[y], pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int x = 0; x < pins.Length; x++){
                Console.WriteLine(FormatToPin(pins[x]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; d < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d + 1))
                    continue;
                int attempt = ChangeDigit(input, d + 1, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1].ToString());
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}


using System;
using System.Collections.Generic;

/*
The first line contains integer t (1≤t≤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≤n≤10) — the number of Polycarp's bank cards.
The next n lines contain the PIN codes p1,p2,…,pn — one per line. The length of each of them is 4.
All PIN codes consist of digits only.

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
*/

public class PinCode{
    static void Main(string[] args){
        PinSolve();
    }

    static void PinSolve(){
        int t = int.Parse(Console.ReadLine());
        int[][] p = new int[t][];

        //gets the pins from each "chunk"
        for(int i = 0; i < t i++){
            int chunk = int.Parse(Console.ReadLine());
            int[] buffer = new int[chunk];
            for(int x = 0; x < chunk; x++){
                buffer[x] = int.Parse(Console.ReadLine());
            }
            p[i] = buffer;
        }
        //Retrieving data complete

        //Iterating through each pin group
        for(int i = 0; i < p.Length; i++){
            int[] pins = p[i];

            //what to do for each pin array
            Array.Sort(pins.Sort());

            int changes = 0;

            while(!Distinct(pins)){
                for(int i = 0; i < pins.Length; i ++){
                    int current = pins[i];
                    //Compares one value with every other value above it (so no repeats with values below it)
                    //VV These are all the values above it
                    for(int x = i + 1; i < pins.Length; x ++){
                        //Same number Detected
                        //Changes the upper number because the lower number will not be checked any more
                        if(current == pins[x]){
                            changes++;
                            pins[x] = GetDistinct(pins[x], in pins);
                        }
                    }
                }
            }
            //everything is distinct
            Console.WriteLine(changes);
            for(int i = 0; i < pins.Length; i++){
                Console.WriteLine(FormatToPin(pins[i]));
            }
        }
    }

    static string FormatToPin(int n){
        string str = n.ToString();
        while(str.Length < 4){
            str = "0" + str;
        }
        return str;
    }

    //returns a distinct 4 digit int
    static int GetDistinct(int input, in int[] arr){
        //Cycles through digits (dynamic as 0060 becomes 60 - 2 digit), and 0-9 different possible changes for them
        int digits = input.ToString().Length;
        for(int d = 0; i < digits; d++){ //d meaning digit
            for(int i = 0; i < 10; i ++){
                if(i == GetDigit(input, d))
                    continue;
                int attempt = ChangeDigit(input, d, i); //cycles through the digit
                if(!Array.Exists(arr, e => e == attempt)) {//is distinct
                    return attempt;
                }
            }
        }
        return -1;
    }

    //a bit hacky but gets the job done
    static int GetDigit(int n, int d){
        string str = n.ToString();
        return int.Parse(str[d - 1]);
    }

    static int ChangeDigit(int n, int d, int val){
        string str = n.ToString();
        str = str.Substring(0,d - 1) + val.ToString() + str.Substring(d);
        return int.Parse(str);
    }

    static bool Distinct(int[] arr){
        for(int i = 0; i < arr.Length; i++){
            int n = arr[i];
            for(int x = i + 1; x < arr.Length; x++){
                if (n == arr[x])
                    return false;
            }
        }
        return true;
    }
}