//code by Piyush Anand
#include <bits/stdc++.h>
using namespace std;
typedef long long  int ll;
#define PI 3.14159265
#define pii pair<ll,ll>
#define ff first
#define ss second
#define mm " "
#define frev for(ll i=n-1;i>=0;i--)
#define inloop for(ll i=0;i<n;i++)cin>>a[i];
#define fa(x,v) for(auto x:v)
#define MM " "
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define f0 for(ll i=0;i<n;i++)
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define f1 for(ll i=1;i<=n;i++)
#define VP vector< pii >
#define Sort(v) sort(v.begin(),v.end())
#define test ll T;cin>>T;while(T--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define pb push_back
#define pr cout<<'\n'
 const ll MOD=1000000000+7;
const ll MOD1 = 998244353;
#define vec vector<ll>
#define vecs vector<string>
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

ll strTo(string s)
{
    stringstream tmp(s);
    ll x = 0;
    tmp >> x;

return x;
}

string NoTo(ll n)
{
    ostringstream str1;
    str1 << n;
    string ans = str1.str();
    return ans;
}

vector<bool>sieve(1000000,true);
void Sieve(){
 sieve[0]=false;
 sieve[1]=false;
 for(ll i=2;i*i<=1000000;i++){
  if(sieve[i]==true){
   for(ll j=i*i;j<1000000;j+=i)
    sieve[j]=false;
  }
 }
}

  ll lcm(ll a, ll b)
 {
    return (a*b)/gcd(a, b);
 }

ll arrlcm(ll arr[], ll n)
{
    // Initialize result
    ll ans = arr[0];

    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (ll i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}

ll arrgcd(ll arr[], ll n)
{
    ll result = arr[0];
    for (ll i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}

ll nCr(ll n, ll r)
{
    ll ans=1;
    f(i,0,r)
    {
        ans*=n-i;
        ans/=i+1;
    }
    return ans;

}

ll fact(ll n)
{
    if (n == 0)
        return 1;
    return n * fact(n - 1);
}

vec v;
void Divisors(ll n)
{
    for (ll i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {

            if (n/i == i)
               v.pb(i);
            else
                {
                    v.pb(i);
                    v.pb(n/i);
                }
        }

    }
}

ll no_of_divisors(ll n){
 ll c = 0;
 for (ll i = 1; i <= sqrt(n); i++) {
  if (n % i == 0){
   if(n/i==i)
    c=c+1;
   else
    c=c+2;
  }
 }
 return c;
}

 ll pwrn(ll x,ll y){
 if (y == 0)
  return 1;
 else if (y % 2 == 0)
  return pwrn(x, y / 2) * pwrn(x, y / 2);
 else
  return x * pwrn(x, y / 2) * pwrn(x, y / 2);
}

 ll pwr(ll a, ll b){
 ll res=1;
 while(b>0){
  if(b&1)
   res=res*a;
  a*=a;
  b>>=1;
 }
 return res;
}

ll pwrm(ll a, ll b, ll m){
 a%=m;
 ll res=1;
 while(b>0){
  if(b&1)
   res=res*a%m;
  a=a*a%m;
  b>>=1;
 }
 return res;
}

ll digits(ll n)
{
    ll x = floor(log10(n)) + 1;
    return x;
}

vec prf;
void primeFactors(ll n)
{
    if(n%2==0)
    prf.pb(2);
    while (n % 2 == 0)
    {
      //  cout << 2 << " ";
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n

        if(n%i==0)
        prf.pb(i);
        while (n % i == 0)
        {
          //  cout << i << " ";
            n = n/i;
        }
    }
    if (n > 1)
        prf.pb(n);
}

int main()
{

    fast;

   test{

       ll n;
       cin>>n;
       map<string,ll> m;
       vector <string> v;
       string tmp;
       f(i,0,n)
       {
           cin>>tmp;
           v.pb(tmp);
           m[tmp]++;
       }
       ll ans=0;
       for(ll i=0;i<v.size();i++)
       {
           if(m[v[i]]>1)
           {

                   string tmp=v[i];
                   string tmp1=v[i];
                   m[v[i]]--;
                   ll c1=0,c2=0;
                   while(m.find(tmp)!=m.end()&&tmp[3]!=9)
                   {
                       c1++;
                       tmp.pop_back();
                         tmp+=(char)(tmp[3]+c1+48);

                   }

                    while(m.find(tmp1)!=m.end()&&tmp1[3]!=0)
                   {
                        c2++;
                        tmp1.pop_back();
                         tmp1+=(char)(tmp1[3]-c2+48);

                   }
                  if(c1>0){
                  m[tmp]++;
                  v[i]=tmp;}
                  else{
                  m[tmp1]++;
                  v[i]=tmp1;}
          //  cout<<tmp1<<'\n';
                    ans+=1;

           }
       }
       cout<<ans<<"\n";
       f(i,0,v.size())
       cout<<v[i]<<"\n";

   }

cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
   return 0;

}

/*

   ll n;
        cin>>n;
       string a,b;
       cin>>a>>b;
       if(a==b)
       cout<<"0\n";
       else
       {
           vec v;

           rf(i,n-1,0)
           {
               if(a[i]!=b[i]){
                 //  cout<<i<<endl;
               if(b[i]==a[0]){
               // v.pb(1);
                v.pb(1);
                v.pb(i+1);
                if(a[0]=='1')
                a[0]='0';
                else
                a[0]='1';

                f(j,0,i+1)
                {
                    if(a[j]=='1')
                    a[j]='0';
                    else
                    a[j]='1';
                }
                f(j,0,i/2+1)
                swap(a[j],a[i-j]);

                }
                else
                {
                   // v.pb(1);
                    v.pb(i+1);
                  //  a[0]=b[i];
                f(j,0,i+1)
                {
                    if(a[j]=='1')
                    a[j]='0';
                    else
                    a[j]='1';
                }
                f(j,0,i/2+1)
                swap(a[j],a[i-j]);
                }

               }

           }
           cout<<v.size()<<" ";
           for(auto it: v)
           cout<<it<<" ";
           cout<<"\n";
       }

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		ans = 0;
		for(int i = 1; i <= n; i++) cin >> p[i];
		for(int i = 1; i <= n; i++)
		{
			if(!vis[p[i]]) vis[p[i]] = 1;
			else
			{
				for(int j = 0; j < 10; j++)
				{
					p[i][3] = j + '0';
					if(!vis[p[i]])
					{
						ans++;
						break;
					}
				}
				vis[p[i]] = 1;
				//ans++;
			}
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		ans = 0;
		for(int i = 1; i <= n; i++) cin >> p[i];
		for(int i = 1; i <= n; i++)
		{
			if(!vis[p[i]]) vis[p[i]] = 1;
			else
			{
				while(vis[p[i]])
				{
					int x = p[i][0] - '0';
					p[i][0] = (x + 1) % 10 + '0';
				}
				vis[p[i]] = 1;
				ans++;
			}
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		ans = 0;
		for(int i = 1; i <= n; i++)
		{
			cin >> p[i];
			vis[p[i]]++;
			if(vis[p[i] > 1]) ans++;
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++)
		{
			if(vis[p[i]] < 2) continue;
			else
			{
				vis[p[i]]--;
				for(int j = 0; j < 10; j++)
				{
					p[i][3] = j + '0';
					if(!vis[p[i]])
					{
						vis[p[i]] = 1;
						break;
					}
				}
			}
		}
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		ans = 0;
		for(int i = 1; i <= n; i++)
		{
			cin >> p[i];
			vis[p[i]]++;
			if(vis[p[i]] > 1) ans++;
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++)
		{
			if(vis[p[i]] < 2) continue;
			else
			{
				vis[p[i]]--;
				for(int j = 0; j < 10; j++)
				{
					p[i][3] = j + '0';
					if(!vis[p[i]])
					{
						vis[p[i]] = 1;
						break;
					}
				}
			}
		}
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis, cnt;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		cnt.clear();
		ans = 0;
		for(int i = 1; i <= n; i++) cin >> p[i], cnt[p[i]]++;
		for(int i = 1; i <= n; i++)
		{
			ans += cnt[p[i]] - 1;
			cnt[p[i]] = 1;
		}
		for(int i = 1; i <= n; i++)
		{
			if(!vis[p[i]]) vis[p[i]] = 1;
			else
			{
				while(vis[p[i]])
				{
					int x = p[i][0] - '0';
					p[i][0] = (x + 1) % 10 + '0';
				}
				vis[p[i]] = 1;
				//ans++;
			}
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis, cnt;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		cnt.clear();
		ans = 0;
		for(int i = 1; i <= n; i++) cin >> p[i], cnt[p[i]]++;
		for(int i = 1; i <= n; i++)
		{
			ans += cnt[p[i]] - 1;
			cnt[p[i]] = 1;
		}
		for(int i = 1; i <= n; i++)
		{
			if(!vis[p[i]]) vis[p[i]] = 1;
			else
			{
				for(int j = 0; j < 10; j++)
				{
					p[i][0] = j + '0';
					if(!vis[p[i]]) break;
				}
				vis[p[i]] = 1;
				//ans++;
			}
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, ans;
string p[12];
map<string, int> vis;
int main()
{
    std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		vis.clear();
		ans = 0;
		for(int i = 1; i <= n; i++) cin >> p[i], vis[p[i]]++;
		for(int i = 1; i <= n; i++)
		{
			ans += vis[p[i]] - 1;
			vis[p[i]] = 1;
		}
		for(int i = 1; i <= n; i++)
		{
			if(!vis[p[i]]) vis[p[i]] = 1;
			else
			{
				while(vis[p[i]])
				{
					int x = p[i][0] - '0';
					p[i][0] = (x + 1) % 10 + '0';
				}
				vis[p[i]] = 1;
				//ans++;
			}
		}
		cout << ans << endl;
		for(int i = 1; i <= n; i++) cout << p[i] << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<string,int>mp;
map<string,pair<int,int> >M;
vector<string>v;
string str[maxn];
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();M.clear();v.clear();
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>str[i];
            mp[str[i]]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            string s=str[i];
            if(mp[s]==1)v.push_back(s);
            else{
                ans++;
                int flag=1;
                for(int j=0;j<=3&&flag;j++){
                    for(int k=0;k<=9&&flag;k++){
                        string ss=s;
                        ss[j]='0'+k;
                        if(mp[ss]==0)mp[ss]=1,v.push_back(ss),flag=0;
                    }
                }
                mp[s]--;
            }
        }
        cout<<ans<<endl;
        for(auto i:v)cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<int,int>mp;
vector<int>v;
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();
        v.clear();
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            int a;cin>>a;
            if(mp.count(a))mp[a]++,v.push_back(a);
            else{
                ans++;
                int k=a%10;
                for(int j=0;j<10;j++){
                    if(mp.count(a-k+j)==0){
                        mp[a-k+j]++;
                        v.push_back(a-k+j);
                        break;
                    }
                }
            }
        }
        cout<<ans<<endl;
        for(auto i:v)printf("%04d\n",i);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<string,int>mp;
map<string,pair<int,int> >M;
vector<string>v;
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();M.clear();v.clear();
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            string s;cin>>s;
            if(mp.count(s)==0)mp[s]=1,v.push_back(s);
            else{
                ans++;
                int flag=1;
                for(int j=0;j<=3&&flag;j++){
                    for(int k=0;k<=9&&flag;k++){
                        string ss=s;
                        ss[j]='0'+k;
                        if(mp.count(ss)==0)mp[ss]=1,v.push_back(ss),flag=0;
                    }
                }
            }
        }
        cout<<ans<<endl;
        for(auto i:v)cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<string,int>mp;
map<string,pair<int,int> >M;
vector<string>v;
string str[maxn];
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();M.clear();v.clear();
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>str[i];
            mp[str[i]]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            string s=str[i];
            if(mp.count(s)==1)v.push_back(s);
            else{
                ans++;
                int flag=1;
                for(int j=0;j<=3&&flag;j++){
                    for(int k=0;k<=9&&flag;k++){
                        string ss=s;
                        ss[j]='0'+k;
                        if(mp.count(ss)==0)mp[ss]=1,v.push_back(ss),flag=0;
                    }
                }
                mp[s]--;
            }
        }
        cout<<ans<<endl;
        for(auto i:v)cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<int,int>mp;
vector<int>v;
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();
        v.clear();
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            int a;cin>>a;
            if(mp.count(a)==0)mp[a]++,v.push_back(a);
            else{
                ans++;
                int k=a%10;
                for(int j=0;j<10;j++){
                    if(mp.count(a-k+j)==0){
                        mp[a-k+j]++;
                        v.push_back(a-k+j);
                        break;
                    }
                }
            }
        }
        cout<<ans<<endl;
        for(auto i:v)printf("%04d\n",i);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<string,int>mp;
map<string,pair<int,int> >M;
vector<string>v;
string str[maxn];
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();M.clear();v.clear();
        int n;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>str[i];
            mp[s]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            string s=str[i];
            if(mp.count(s)==1)v.push_back(s);
            else{
                ans++;
                int flag=1;
                for(int j=0;j<=3&&flag;j++){
                    for(int k=0;k<=9&&flag;k++){
                        string ss=s;
                        ss[j]='0'+k;
                        if(mp.count(ss)==0)mp[ss]=1,v.push_back(ss),flag=0;
                    }
                }
                mp[s]--;
            }
        }
        cout<<ans<<endl;
        for(auto i:v)cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<int,int>mp;
vector<int>v;
int a[maxn];

int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();
        v.clear();
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i],mp[a[i]]++;
        int ans=0;
        for(int i=1;i<=n;i++){
            int aa=a[i];
            if(mp[aa]==1)v.push_back(aa);
            else{
                ans++;
                int k=aa%10;
                for(int j=0;j<10;j++){
                    if(mp.count(aa-k+j)==0){
                        mp[aa-k+j]++;
                        v.push_back(aa-k+j);
                        break;
                    }
                }
                mp[aa]--;
            }
        }
        cout<<ans<<endl;
        for(auto i:v)printf("%04d\n",i);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
typedef long long ll;
map<string,int>mp;
map<string,pair<int,int> >M;
vector<string>v;
int main() {
    int t;
    cin>>t;
    while(t--){
        mp.clear();M.clear();v.clear();
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            string s;cin>>s;
            if(mp.count(s)==0)mp[s]=1,v.push_back(s);
            else{
                ans++;
                int flag=1;
                for(int j=0;j<3&&flag;j++){
                    for(int k=0;k<=9&&flag;k++){
                        string ss=s;
                        ss[j]='0'+k;
                        if(mp.count(ss)==0)mp[ss]=1,v.push_back(ss),flag=0;
                    }
                }
            }
        }
        cout<<ans<<endl;
        for(auto i:v)cout<<i<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    char i;
    cin>>t;
    vector<string>v,v1;
    map<string,int>mp;
    while(t--)
    {
        cin>>n;
        string s;
        for(int i=0;i<n;i++){
            cin>>s;
            v.push_back(s);
            mp[s]++;
        }
        int coun=0;
        for(int j=0;j<n;j++)
        {
            s=v[j];
            if(mp[v[j]]==1)v1.push_back(v[j]);
            else
            {
                mp[v[j]]--;
                for(i=0;i<=9;i++)
                {
                    if(s[3]!=i+'0')
                    {
                        s[3]=i+'0';
                        if(mp[s]==0)
                        {
                            v1.push_back(s);coun++;
                            mp[s]++;break;
                        }
                    }
                }

            }

        }
        cout<<coun<<endl;
        for(int i=0;i<n;i++)
            cout<<v1[i]<<endl;

        v.clear();
        v1.clear();
        mp.clear();

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    char i;
    cin>>t;
    while(t--)
    {
       string s,s1;
        map<string,int>mp;
        vector<string>v;
        map<string,int> :: iterator it;
        cin>>n;
        int coun=0;
        while(n--)
        {
            cin>>s;
            s1=s;
            int len=s.size();
            if(mp[s]==0){mp[s]++;v.push_back(s);}
            else
            {
                for(i=0;i<=9;i++)
                {
                    if(s[len-1]!=i+'0')
                    {
                        s[len-1]=i+'0';
                         if(mp[s]==0)
                        {
                            mp[s]++;
                            coun++;
                            v.push_back(s);
                            break;
                        }
                    }
                }

            if(s==s1)
            {
                for(i=0;i<=9;i++)
                {
                    if(s[0]!=i+'0')
                    {
                        s[0]=i='0';
                        if(mp[s]==0)
                        {
                            mp[s]++;
                            coun++;
                            v.push_back(s);
                            break;
                        }

                    }
                }

            }
            }

        }
            cout<<coun<<endl;
           for(int i=0;i<v.size();i++)
            cout<<v[i]<<endl;

}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    string x;
    cin>>t;
    while(t--)
    {
        map<string,int>mp;
        vector<string>v;
        int i=1,coun=0;
        cin>>n;
        int m=n,j=0;
        while(n--)
        {
            cin>>x;
            if(mp[x]==0)
                mp[x]++;
            else
            {
                coun++;
            }
           v.push_back(x);
        }
        cout<<coun<<endl;
        for(i=0;i<v.size();i++)
        {
            if(j>9)
                j=0;
            if(mp[v[i]]==1)
            {
                cout<<v[i]<<endl;
                mp[v[i]]=0;
            }
            else
            {
                x=v[i];
                x[0]=j+48;
                j++;
                cout<<x<<endl;
            }

        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    string x;
    cin>>t;
    while(t--)
    {
        map<string,int>mp;
        vector<string>v;
        int i=1,coun=0;
        cin>>n;
        int m=n,j=0;
        while(n--)
        {
            cin>>x;
            if(mp[x]==0)
                mp[x]++;
            else
            {
                coun++;
            }
           v.push_back(x);
        }
        cout<<coun<<endl;
        for(i=0;i<v.size();i++)
        {
            if(mp[v[i]]==1)
            {
                cout<<v[i]<<endl;
                mp[v[i]]=0;
            }
            else
            {
                x=v[i];
                x[0]=j+48;
                cout<<x<<endl;
            }
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    char i;
    cin>>t;
    vector<string>v,v1;
    map<string,int>mp;
    while(t--)
    {
        cin>>n;
        string s;
        for(int i=0;i<n;i++){
            cin>>s;
            v.push_back(s);
            mp[s]++;
        }
        int coun=0;
        for(int j=0;j<n;j++)
        {
            s=v[j];
            if(mp[v[j]]==1)v1.push_back(v[j]);
            else
            {
                mp[v[i]]--;
                for(i=0;i<=9;i++)
                {
                    if(s[3]!=i+'0')
                    {
                        s[3]=i+'0';
                        if(mp[s]==0)
                        {
                            v1.push_back(s);coun++;
                            mp[s]++;break;
                        }
                    }
                }

            }

        }
        cout<<coun<<endl;
        for(int i=0;i<n;i++)
            cout<<v1[i]<<endl;

        v.clear();
        v1.clear();
        mp.clear();

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    char i;
    cin>>t;
    while(t--)
    {
       string s,s1;
        map<string,int>mp;
        map<string,int> :: iterator it;
        cin>>n;
        int coun=0;
        while(n--)
        {
            cin>>s;
            s1=s;
            int len=s.size();
            if(mp[s]==0){mp[s]++;}
            else
            {
                for(i=0;i<=9;i++)
                {
                    if(s[len-1]!=i+'0')
                    {
                        s[len-1]=i+'0';
                         if(mp[s]==0)
                        {
                            mp[s]++;
                            coun++;
                            break;
                        }
                    }
                }

            if(s==s1)
            {
                for(i=0;i<=9;i++)
                {
                    if(s[0]!=i+'0')
                    {
                        s[0]=i='0';
                        if(mp[s]==0)
                        {
                            mp[s]++;
                            coun++;
                            break;
                        }

                    }
                }

            }
            }

        }
            cout<<coun<<endl;
            for(it=mp.begin();it!=mp.end();it++)
                cout<<it->first<<endl;

}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    string x;
    cin>>t;
    while(t--)
    {
        map<string,int>mp;
        vector<string>v;
        int i=1,coun=0;
        cin>>n;
        int m=n,j=0;
        while(n--)
        {
            cin>>x;
            if(mp[x]==0)
                mp[x]++;
            else
            {
                coun++;
            }
           v.push_back(x);
        }
        cout<<coun<<endl;
        for(i=0;i<v.size();i++)
        {
            if(mp[v[i]]==1)
            {
                cout<<v[i]<<endl;
                mp[v[i]]=0;
            }
            else
            {
                x=v[i];
                x[0]=j+48;
                j++;
                cout<<x<<endl;
            }
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    cin>>t;
    char x[5];
    while(t--)
    {
        map<string,int>mp;
        map<string,int>:: iterator it;
        cin>>n;
        int coun=0,i=0,j=0;
        while(n--)
        {
            cin>>x;

            if(mp[x]==0)
            {
                mp[x]++;
            }
            else
            {
                if(i>9)
                    i=0;
                if(j>3)
                    j=0;

                x[j++]=i+48;
                mp[x]++;
                coun++;
            }
        }
        cout<<coun<<endl;
        for(it=mp.begin();it!=mp.end();it++)
            cout<<it->first<<endl;
        mp.clear();

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    cin>>t;
    char x[5];
    while(t--)
    {
        map<string,int>mp;
        map<string,int>:: iterator it;
        cin>>n;
        int coun=0,i=0,j=0;
        while(n--)
        {
            cin>>x;
            if(i>9)
                i=0;
            if(j>3)
                j=0;
            if(mp[x]==0)
            {
                mp[x]++;
                //cout<<"YES"<<endl;
            }
            else
            {
                x[j++]=i+48;
                i++;
                mp[x]++;
                coun++;
                //cout<<coun<<endl;
            }
        }
        cout<<coun<<endl;
        for(it=mp.begin();it!=mp.end();it++)
            cout<<it->first<<endl;
        mp.clear();

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        map<string,int>mp;
        string a[n+1];
        for(i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        int coun=0;
        for(i=0;i<n;i++){
            if(mp[a[i]]>1){
                    coun++;
                mp[a[i]]--;
                for(int j=0;j<4;j++)
                {
                   int l=0;
                   for(int k=0;k<4;k++)
                   {
                       a[i][j]=l+48;
                       l++;
                       if(mp[a[i]]==0)break;
                   }
                    if(mp[a[i]]==0)break;
                }mp[a[i]]++;
            }

        }
        cout<<coun<<endl;
        for(i=0;i<n;i++)
            cout<<a[i]<<endl;

    }
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
long int t;
cin>>t;
while(t--)
{
  long int n,count=0;
  cin>>n;
  long int arr[10]={0},i,j;
  string s[n];
  for(i=0;i<n;i++)
  {
    cin>>s[i];
    arr[s[i][0]-'0']=1;
  }
  vector<long int>v;
  for(i=0;i<10;i++)
  {
  if(arr[i]==0)
  v.push_back(i);
  }
  long int k=0;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
  {
    if(s[i]==s[j])
    {
      s[j][0]=char('0'+v[k]);
      k++;
      count++;
    }
  }
}
cout<<count<<endl;
for(i=0;i<n;i++)
  cout<<s[i]<<endl;
 }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
     int cnt=0;
     int n;
     cin>>n;
     string ar[n];
     for(int i=0;i<n;i++)
     cin>>ar[i];
     for(int i=0;i<n-1;i++)
     {
       for(int j=i+1;j<n;j++)
       {
           if(ar[i]==ar[j])
           {
               cnt++;
           ar[j][3]=j+48;
           }
       }
     }
     cout<<cnt<<endl;
     for(int i=0;i<n;i++)
     cout<<ar[i]<<endl;
 }
 return 0;
}


#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
     int cnt=0;
     int n;
     cin>>n;
     string ar[n];
     for(int i=0;i<n;i++)
     cin>>ar[i];
     for(int i=0;i<n;i++)
     {
       for(int j=0;j<n;j++)
       {
           if(ar[i]==ar[j]&&j!=i)
           {
               if(ar[i][3]!=i+48)
               cnt++;
           ar[i][3]=i+48;

           }
       }
     }
     cout<<cnt<<endl;
     for(int i=0;i<n;i++)
     cout<<ar[i]<<endl;
 }
 return 0;
}


#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
     int cnt=0;
     int n;
     cin>>n;
     string ar[n];
     for(int i=0;i<n;i++)
     cin>>ar[i];
     for(int i=0;i<n;i++)
     {
       for(int j=0;j<n&&j!=i;j++)
       {
           if(ar[i]==ar[j])
           {
               cnt++;
           ar[i][3]=i+48;

           }
       }
     }
     cout<<cnt<<endl;
     for(int i=0;i<n;i++)
     cout<<ar[i]<<endl;
 }
 return 0;
}


#include <iostream>
using namespace std;
int main()
{
long int t;
cin>>t;
while(t--)
{
  long int n,count=0;
  cin>>n;
  long int arr[10]={0},i,j;
  string s[n];
  for(i=0;i<n;i++)
  {
    cin>>s[i];
    arr[s[i][0]-'0']=1;
  }
  vector<long int>v;
  for(i=0;i<10;i++)
  if(arr[i]==0)
  v.push_back(i);
  long int k=0;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
  {
    if(s[i]==s[j])
    {
      s[j][0]=char('0'+v[k]);
      k++;
      count++;
    }
  }
}
cout<<count<<endl;
for(i=0;i<n;i++)
  cout<<s[i]<<endl;
 }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
     int cnt=0;
     int n;
     cin>>n;
     string ar[n];
     for(int i=0;i<n;i++)
     cin>>ar[i];
     for(int i=0;i<n-1;i++)
     {
       for(int j=i+1;j<n;j++)
       {
           if(ar[i]==ar[j])
           {
               cnt++;
           ar[j][3]=j+48;
           ar[i][3]=i+48;
           }
       }
     }
     cout<<cnt<<endl;
     for(int i=0;i<n;i++)
     cout<<ar[i]<<endl;
 }
 return 0;
}


#include <iostream>
using namespace std;
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
     int cnt=0;
     int n;
     cin>>n;
     string ar[n];
     for(int i=0;i<n;i++)
     cin>>ar[i];
     for(int i=0;i<n-1;i++)
     {
       for(int j=i+1;j<n;j++)
       {
           if(ar[i]==ar[j])
           {
               cnt++;
           ar[i][3]=i+48;

           }
       }
     }
     cout<<cnt<<endl;
     for(int i=0;i<n;i++)
     cout<<ar[i]<<endl;
 }
 return 0;
}


#include <iostream>
using namespace std;
int main()
{
long int t;
cin>>t;
while(t--)
{
  long int n,count=0;
  cin>>n;
  long int arr[10]={0},i,j;
  string s[n];
  for(i=0;i<n;i++)
  {
    cin>>s[i];
    arr[s[i][0]-'0']=1;
  }
  vector<long int>v;
  for(i=0;i<10;i++)
  {
  if(arr[i]==0)
  v.push_back(i);
  }
  long int k=0;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
  {
    if(s[i]==s[j])
    {
      s[j][0]=char('0'+v[k]);
      k++;
      count++;
    }
  }
}
cout<<count<<endl;
for(i=0;i<n;i++)
  cout<<s[i]<<endl;
 }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        int y=s[i][3];
        k[y]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    continue;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        k[s[i][3]]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    continue;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    ll u=0;
    for(u=0;u<t;u++)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        k[s[i][3]]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    else
    {
        ll c=0;
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                ll e=0;
                char r='0';
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        int y=int(s[i][3]-'0');
        k[y]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    continue;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        k[s[i][3]]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    ll u=0;
    for(u=0;u<t;u++)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        k[s[i][3]]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    int n;
    cin>>n;
    map<string,int> p;
    string s[n];
    int k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        int y=(int)s[i][3];
        k[y]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    continue;
    }
    else
    {
      int c=0,e=0;
        char r='0';
        for(int i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const double pi = 3.14159265359;
int main() {
    ll t;
    cin>>t;
    while(t-->0)
    {
    ll n;
    cin>>n;
    map<string,ll> p;
    string s[n];
    ll k[10];
    memset(k,0,sizeof(k));
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        k[s[i][3]]=1;
        p[s[i]]++;
    }
    if(p.size()==n)
    {
        cout<<0<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    else
    {
        ll c=0,e=0;
        char r='0';
        for(ll i=0;i<n;i++)
        {
            if(p[s[i]]>1)
            {
                p[s[i]]--;
                c++;
                while(k[e]==1&&e<10)
                    {
                        e++;
                        r++;
                    }
                s[i][3]=r;
                k[e]=1;
            }
        }
        cout<<c<<endl;
        for(ll i=0;i<n;i++)
            cout<<s[i]<<endl;
    }
    }
return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<pair<string, ll>> s(q);
        vector<vector<pair<string, ll>>> ans(11);
        vector<set<char>> v(4);
        for (int i = 0; i < q; i++) {
            cin >> s[i].first;
            s[i].second = i;
        }
        for (int i = 0; i < q; i++) {
            for (int j = 0; j < s[i].first.length(); j++) {
                v[j].insert((s[i].first)[j]);
            }
        }
        sort(s.begin(), s.end());
        ll y = 0, i = 0;
        for (i; i < q - 1; i++) {
            if (s[i].first == s[i + 1].first) {
                ans[y].push_back(s[i]);
            } else {
                ans[y].push_back(s[i]);
                y++;
            }
        }
        if (s[s.size() - 1].first == s[s.size() - 2].first) {
            ans[y].push_back(s[s.size() - 1]);
        } else {
            ans[y].push_back(s[s.size() - 1]);
        }
        y++;
        ll cnt = 0;
        for (int i = 0; i < y; i++) {
            char ch = '0';
            // char haa = (ans[i][ans[i].size() - 1].first)[0];
            if (ans[i].size() == 1) continue;
            for (int q = 0; q < ans[i].size() - 1; q++) {
                while (v[0].find(ch) != v[0].end()) ch++;
                if (ch > '9') {
                    ch = '0';
                    while (v[1].find(ch) != v[1].end()) ch++;
                    if (ch <= '9') {
                        (ans[i][q].first)[1] = ch;
                        v[1].insert(ch);
                        cnt++;
                        ch++;
                        continue;
                    }
                }
                if (ch > '9') {
                    ch = '0';
                    while (v[2].find(ch) != v[2].end()) ch++;
                    if (ch <= '9') {
                        (ans[i][q].first)[2] = ch;
                        cnt++;
                        v[2].insert(ch);
                        ch++;
                        continue;
                    }
                }
                if (ch > '9') {
                    ch = '0';
                    while (v[3].find(ch) != v[3].end()) ch++;
                    if (ch <= '9') {
                        (ans[i][q].first)[3] = ch;
                        v[3].insert(ch);
                        cnt++;
                        ch++;
                        continue;
                    }
                }
                // cout << (ans[i][q].first)[0] << endl;
                (ans[i][q].first)[0] = ch;
                v[0].insert(ch);
                cnt++;
                ch++;
            }
        }
        cout << cnt << endl;
        for (int i = 0; i < q; i++) {
            bool isfound = false;
            for (int yy = 0; yy < y; yy++) {
                for (int yyy = 0; yyy < ans[yy].size(); yyy++) {
                    if (ans[yy][yyy].second == i) {
                        cout << ans[yy][yyy].first << endl;
                        isfound = true;
                        break;
                    }
                }
                if (isfound) break;
            }
        }

        /*  string haa = ans[0][0].first;
          cout << haa;*/
    }
    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<string> s(q);
        map<string, ll> mp;
        for (int i = 0; i < q; i++) {
            cin >> s[i];
            mp[s[i]]++;
        }
        ll cnt = 0;
        for (size_t i = 0; i < q; i++) {
            /* code */
            ll indx = 0;
            if (mp[s[i]] >= 2) {
                mp[s[i]]--;
                while (indx < 4) {
                    char a = '0', m;
                    bool isfound = false;
                    while (mp[s[i]]) {
                        if (s[i][indx] != a) {
                            m = s[i][indx];
                            s[i][indx] = a;
                            if (mp[s[i]]) s[i][indx] = m;
                        }
                        a++;
                        if (a > '9') {
                            isfound = true;
                            break;
                        }
                    }
                    if (isfound) indx++;
                    if (!mp[s[i]]) {
                        mp[s[i]]++;
                        break;
                    }
                }
                cnt++;
            }
        }
        cout << cnt << '\n';
        for (int i = 0; i < q; i++) {
            cout << s[i] << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<pair<string, ll>> s(q);
        vector<vector<pair<string, ll>>> ans(11);
        for (int i = 0; i < q; i++) {
            cin >> s[i].first;
            s[i].second = i;
        }
        sort(s.begin(), s.end());
        ll y = 0, i = 0;
        for (i; i < q - 1; i++) {
            if (s[i].first == s[i + 1].first) {
                ans[y].push_back(s[i]);
            } else {
                ans[y].push_back(s[i]);
                y++;
            }
        }
        if (s[s.size() - 1].first == s[s.size() - 2].first) {
            ans[y].push_back(s[s.size() - 1]);
        } else {
            ans[y].push_back(s[s.size() - 1]);
        }
        y++;
        ll cnt = 0;
        for (int i = 0; i < y; i++) {
            char ch = '0';
            char haa = (ans[i][ans[i].size() - 1].first)[0];
            if (ans[i].size() == 1) continue;
            for (int q = 0; q < ans[i].size(); q++) {
                if (haa == ch) ch++;
                // cout << (ans[i][q].first)[0] << endl;
                (ans[i][q].first)[0] = ch;
                cnt++;
                ch++;
            }
        }
        cout << cnt << endl;
        for (int i = 0; i < q; i++) {
            bool isfound = false;
            for (int yy = 0; yy < y; yy++) {
                for (int yyy = 0; yyy < ans[yy].size(); yyy++) {
                    if (ans[yy][yyy].second == i) {
                        cout << ans[yy][yyy].first << endl;
                        isfound = true;
                        break;
                    }
                }
                if (isfound) break;
            }
        }

        /*  string haa = ans[0][0].first;
          cout << haa;*/
    }
    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<pair<string, ll>> s(q);
        vector<vector<pair<string, ll>>> ans(11);
        for (int i = 0; i < q; i++) {
            cin >> s[i].first;
            s[i].second = i;
        }
        sort(s.begin(), s.end());
        ll y = 0, i = 0;
        for (i; i < q - 1; i++) {
            if (s[i].first == s[i + 1].first) {
                ans[y].push_back(s[i]);
            } else {
                ans[y].push_back(s[i]);
                y++;
            }
        }
        if (s[s.size() - 1].first == s[s.size() - 2].first) {
            ans[y].push_back(s[s.size() - 1]);
        } else {
            ans[y].push_back(s[s.size() - 1]);
        }
        y++;
        ll cnt = 0;
        for (int i = 0; i < y; i++) {
            char ch = '0';
            char haa = (ans[i][ans[i].size() - 1].first)[0];
            if (ans[i].size() == 1) continue;
            for (int q = 0; q < ans[i].size() - 1; q++) {
                if ((ans[i][q].first)[0] == ch || haa == ch) ch++;
                // cout << (ans[i][q].first)[0] << endl;
                (ans[i][q].first)[0] = ch;
                cnt++;
                ch++;
            }
        }
        cout << cnt << endl;
        for (int i = 0; i < q; i++) {
            bool isfound = false;
            for (int yy = 0; yy < y; yy++) {
                for (int yyy = 0; yyy < ans[yy].size(); yyy++) {
                    if (ans[yy][yyy].second == i) {
                        cout << ans[yy][yyy].first << endl;
                        isfound = true;
                        break;
                    }
                }
                if (isfound) break;
            }
        }

        /*  string haa = ans[0][0].first;
          cout << haa;*/
    }
    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<string> s(q);
        map<string, ll> mp;
        vector<string> v;
        for (int i = 0; i < q; i++) {
            cin >> s[i];
            mp[s[i]]++;
        }
        ll cnt = 0;
        for (size_t i = 0; i < q; i++) {
            /* code */
            ll indx = 0;
            if (mp[s[i]] >= 2) {
                mp[s[i]]--;
                while (indx < 4) {
                    if (mp[s[i]]) {
                        if (indx > 0) {
                            if (s[i][indx - 1] == '0') {
                                s[i][indx - 1] = '9';
                            } else {
                                s[i][indx - 1]--;
                            }
                        }
                        if (s[i][indx] == '9') {
                            s[i][indx] = '0';
                        } else {
                            s[i][indx]++;
                        }
                        indx++;
                    }
                    if (!mp[s[i]]) {
                        mp[s[i]]++;
                        break;
                    }
                }
                cnt++;
            }
        }
        cout << cnt << '\n';
        for (int i = 0; i < q; i++) {
            cout << s[i] << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<pair<string, ll>> s(q);
        vector<vector<pair<string, ll>>> ans(11);
        for (int i = 0; i < q; i++) {
            cin >> s[i].first;
            s[i].second = i;
        }
        sort(s.begin(), s.end());
        ll y = 0;
        for (int i = 0; i < q - 1; i++) {
            if (s[i].first == s[i + 1].first) {
                ans[y].push_back(s[i]);
            } else {
                if (!ans[y].empty()) y++;
                ans[y].push_back(s[i]);
                y++;
            }
        }
        if (s[s.size() - 1].first == s[s.size() - 2].first) {
            ans[y].push_back(s[s.size() - 1]);
        } else {
            ans[y].push_back(s[s.size() - 1]);
        }
        y++;
        ll cnt = 0;
        // cout << y;
        for (int i = 0; i < y; i++) {
            char ch = '0';
            char haa = (ans[i][ans[i].size() - 1].first)[0];
            if (ans[i].size() == 1) continue;
            for (int q = 0; q < ans[i].size(); q++) {
                if (haa == ch)
                    ch++;
                else {
                    (ans[i][q].first)[0] = ch;
                    cnt++;
                    ch++;
                }
            }
        }
        cout << cnt << endl;
        for (int i = 0; i < q; i++) {
            bool isfound = false;
            for (int yy = 0; yy < y; yy++) {
                for (int yyy = 0; yyy < ans[yy].size(); yyy++) {
                    if (ans[yy][yyy].second == i) {
                        cout << ans[yy][yyy].first << endl;
                        isfound = true;
                        break;
                    }
                }
                if (isfound) break;
            }
        }

        /*  string haa = ans[0][0].first;
          cout << haa;*/
    }
    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<pair<string, ll>> s(q);
        vector<vector<pair<string, ll>>> ans(11);
        for (int i = 0; i < q; i++) {
            cin >> s[i].first;
            s[i].second = i;
        }
        sort(s.begin(), s.end());
        ll y = 0, i = 0;
        for (i; i < q - 1; i++) {
            if (s[i].first == s[i + 1].first) {
                ans[y].push_back(s[i]);
            } else {
                ans[y].push_back(s[i]);
                y++;
            }
        }
        if (s[s.size() - 1].first == s[s.size() - 2].first) {
            ans[y].push_back(s[s.size() - 1]);
        } else {
            ans[y].push_back(s[s.size() - 1]);
        }
        y++;
        ll cnt = 0;
        for (int i = 0; i < y; i++) {
            char ch = '0';
            char haa = (ans[i][ans[i].size() - 1].first)[0];
            if (ans[i].size() == 1) continue;
            for (int q = 0; q < ans[i].size() - 1; q++) {
                if (haa == ch) ch++;
                // cout << (ans[i][q].first)[0] << endl;
                (ans[i][q].first)[0] = ch;
                cnt++;
                ch++;
            }
        }
        cout << cnt << endl;
        for (int i = 0; i < q; i++) {
            bool isfound = false;
            for (int yy = 0; yy < y; yy++) {
                for (int yyy = 0; yyy < ans[yy].size(); yyy++) {
                    if (ans[yy][yyy].second == i) {
                        cout << ans[yy][yyy].first << endl;
                        isfound = true;
                        break;
                    }
                }
                if (isfound) break;
            }
        }

        /*  string haa = ans[0][0].first;
          cout << haa;*/
    }
    return 0;
}


#include <bits/stdc++.h>
#define Zero_IQ                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;
istream& in(cin);
ostream& out(cout);
ll minn = INT_MAX;
int main() {
    Zero_IQ ll n;
    cin >> n;
    while (n--) {
        ll q;
        cin >> q;
        vector<string> s(q);
        map<string, ll> mp;
        vector<string> v;
        for (int i = 0; i < q; i++) {
            cin >> s[i];
            mp[s[i]]++;
        }
        ll cnt = 0;
        for (size_t i = 0; i < q; i++) {
            /* code */
            ll indx = 0;
            if (mp[s[i]] >= 2) {
                mp[s[i]]--;
                while (indx < 4) {
                    if (mp[s[i]]) {
                        if (s[i][indx] == '9') {
                            s[i][indx] = '0';
                        } else {
                            s[i][indx]++;
                        }
                        indx++;
                    }
                    if (!mp[s[i]]) {
                        mp[s[i]]++;
                        break;
                    }
                }
                cnt++;
            }
        }
        cout << cnt << '\n';
        for (int i = 0; i < q; i++) {
            cout << s[i] << endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// #define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>1)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t1+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<endl;
rep(i,0,n)
printf("%.4lld\n",a[i]);

}
  return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>1)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t1+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<endl;
rep(i,0,n)
printf("%.4lld\n",a[i]);

}
  return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// #define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>1)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t1+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<'\n';
rep(i,0,n)
printf("%.4lld\n",a[i]);

}
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define DB pop_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define V(a) vector<a>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
void Miden(ll **p1,ll n);
void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m);
void Mpow(ll **p1,ll **ans,ll n,ll y,ll m);
pll Egcd(ll x,ll y);

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

pll Egcd(ll x,ll y)
{
    if(x==0) return MP(0,1);
    pll t=Egcd(y%x,x);
    return MP(t.S-t.F*(y/x),t.F);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    REP(i,0,x)
    {
        REP(j,0,z)
        {
            c[i][j]=0;
            REP(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

int main()
{
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll ntc=1;
    cin>>ntc;
    REP(tc,1,ntc+1)
    {
        //cout<<"Case #"<<tc<<": ";

        ll n;
        cin>>n;
        ll a[n];
        ll x[10000]={};
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
            x[t]++;
        }
        ll ans=0;
        REP(i,0,n)
        {
            if(x[a[i]]>1)
            {
                ll r=1;
                ll f=-1;
                REP(k,0,4)
                {
                    ll t=(a[i]/(r*10))*(r*10)+a[i]%r;
                    REP(j,0,10)
                    {
                        if(x[t+j*r]==0)
                        {
                            f=t+j*r;
                            break;
                        }
                    }
                    r*=10;
                    if(f!=-1) break;
                }
                x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;
            }
        }
        cout<<ans<<'\n';
        REP(i,0,n) printf("%.4lld\n",a[i]);

    }

    return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>0)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t1+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<endl;rep(i,0,n)cout<<a[i]<<endl;

}
  return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>0)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<endl;rep(i,0,n)cout<<a[i]<<" ";
cout<<endl;

}
  return 0;
}


#include<bits/stdc++.h>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include<map>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define vi vector<int>
#define vll vector<long long>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define INF 1e18
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define PI 3.141592653589793238462643
#define BLOCK 555
//ans.resize(unique(ALL(ans)) - ans.begin());

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll gcd(ll  a, ll  b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return (a*b)/(gcd(a, b));
}

 ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}

int cnt[200005]={0};
vector<int> adj[200005];
void factorize(int n)
{
	int count=0;
	map<int,int> fact;
	while(!(n%2))
	{
		n/=2;
		count++;
	}
	if (count)
	fact[2]+=count;
	for(int i=3;i<=sqrt(n);i+=2)
	{
		count=0;
		while((n%i)==0)
		{
			count++;
			n/=i;
		}
		if (count)
		fact[i]+=count;
	}
	if(n>2)
		fact[n]++;
	// for(auto it:fact)
	// {
		// cnt[it.first]++;
		// adj[it.first].pb(it.second);
	// }
}

long long int power(long long int x, int p)
{
    if (p == 0)
        return 1;
    long long int ans = power(x, p / 2);
    ans = ans * ans;
    if (p % 2 == 1)
        ans = ans * x;
    return ans;
}
long long int factorial(long long int n){
    if(n <= 1)
        return 1;
    long long int ans = 1;
    for(ll i=1;i<=n;i++){
        ans = ans * i;
        // ans = ans % B;
    }
    return ans;
}

ll nCr(ll n,ll k){
    ll C[n + 1][k + 1];
    ll i, j;
    for (i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B;
        }
    }
    return C[n][k]%B;
}

ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
vector<ll> countDivisors(ll n)
{
    ll cnt = 0;
    std::vector<ll> v;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
         v.pb(i);
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                {cnt = cnt + 2;
                	v.pb(n/i);}
        }
    }
    return v;
}
ll highestPowerof2(ll n)
{
   ll p = (ll)log2(n);
    return (ll)pow(2, p);
}

bool isPowerOfTwo(ll x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

map<ll,ll> factors(ll n)
 {
        vector<ll> f;
        map<ll,ll> m;
        for (ll x = 2; x*x <= n; x++)
        {
           while (n%x == 0) {
            f.push_back(x);
            m[x]++;
            n /= x; }
        }
    if (n > 1)
     {f.push_back(n);
     	m[n]++;
     }
  return m;
}

ll binarySearch(ll arr[], ll l, ll r, ll x)
{
    if (r >= l) {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
int rub[2000001];
bool ispali(int n){
    int no=n;
    int rev=0;
    while(no>0){
            int ld=no%10;
    no/=10;
        rev=rev*10+ld;
    }
    if(n==rev)
        return true;
    else
        return false;
}
void np(){
for(int i=1;i<=2000000;i++){
    if(ispali(i))
        rub[i]=rub[i-1]+1;
    else
        rub[i]=rub[i-1];
}
}

int pi[2000001];
bool isprime[2000001];
void seive(){
for(int i=4;i<=2000000;i+=2)
    isprime[i]=1;
for(int i=3;i*i<=2000000;i+=2){
    if(!isprime[i]){
        for(int j=i*i;j<=2000000;j+=i)
            isprime[j]=1;
    }
}
for(int i=2;i<=2000000;i++){
    if(!isprime[i])
    pi[i]=pi[i-1]+1;
    else
    pi[i]=pi[i-1];
}
}
int g1;
void bfs( vector<vector<int> > &g , int pos , vector<int> visited )
{
    queue <int> q;
    q.push( pos );
    while( q.size()>0 )
    {
       // cout<<q.front()<<" ";
        if(q.front()==g1){ cout<<"yes";return ;}
        int i = q.front();
        q.pop();
         visited[i]=1;

        for(int j = 0 ; j < g[i].size() ; j++)
        {
            if( visited[ g[i][j] ] == 0 )
            {
                q.push( g[i][j] );
                visited[g[i][j]] = 1;
            }
        }
    }
  return;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }

}

int main()
{
    ani;
     // seive(); np();
int t=1;
cin>>t;
while(t--)
{
	int n;
    cin>>n;
    ll a[n];
    ll x[10000]={0};
    rep(i,0,n)
    {
        cin>>a[i];
        x[a[i]]++;
    }

    ll ans=0;
    rep(i,0,n)
    {
        if(x[a[i]]>1)
        {
             ll r=1;
             ll f=-1;
             rep(k,0,4)
             {
                ll t1=(a[i]/(r*10))*(r*10)+a[i]%r;
                rep(j,0,10)
                {
                    if(x[t1+j*r]==0)
                        {
                            f=t1+j*r;
                            break;
                        }
                }
                r*=10;
                if(f!=-1) break;
             }
             x[a[i]]--;
                a[i]=f;
                x[a[i]]++;
                ans++;

        }
    }

cout<<ans<<'\n';
rep(i,0,n)
printf("%.4lld\n",a[i]);

}
  return 0;
}


#include <bits/stdc++.h>
#define NN 10000
using namespace std;
typedef long long INT;

int p[15];
bool vst[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int test;
	scanf("%d", &test);
	while(test--){
		int n, cnt = 0;
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			scanf("%d", &p[i]);
		}
		for(int i = 0; i < n; i++){
			if(vst[p[i]] == 0) {vst[p[i]]++; continue;}
			while(1){
				int t = 1;
				cnt++;
				if(vst[p[i] + t * 1000] == 0) {p[i] = p[i] + t * 1000; vst[p[i]] = 1; break;}
				if(vst[p[i] + t * 100] == 0 && p[i] % 1000 + t * 100 < 1000) {p[i] = p[i] + t * 100; vst[p[i]] = 1; break;}
				if(vst[p[i] + t * 10] == 0 && p[i] % 100 + t * 10 < 100){p[i] = p[i] + t * 10; vst[p[i]] = 1; break;}
				if(vst[p[i] + t] == 0 && p[i] % 10 + t < 10) {p[i] = p[i] + t; vst[p[i]] = 1; break;}
				t++;
			}
		}
		cout<<cnt<<endl;
		for(int i = 0; i < n; i++){
			if(p[i] < 1000) cout<<'0';
			if(p[i] < 100) cout<<'0';
			if(p[i] < 10) cout<<'0';
			cout<<p[i]<<endl;
		}
	}
	return 0;
}