#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		bool change = false;
		int i = 0;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(find(ar.begin(), ar.end(), s) != ar.end()){
				if(s[i] == '0') s[i] = '9';
				else s[i] = ((s[i] - '0') - 1) + '0';
				i++, c = s[i];
				change = true;
				continue;
			}
			if(s[i] == c && i < 4) i++, c = s[i];
			change = true;
		}
		st.push_back(s);
		if(change) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st;
	while(n--){
		string s;
		cin >> s;
		bool change = false;
		int i = 3;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(s[i] == c && i > 0) i--, c = s[i];
			change = true;
		}
		st.push_back(s);
		if(change) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		bool change = false;
		int i = 0;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(find(ar.begin(), ar.end(), s) != ar.end()){
				if(s[i] == '0') s[i] = '9';
				else s[i] = ((s[i] - '0') - 1) + '0';
				i++, c = s[i];
				continue;
			}
			if(s[i] == c && i < 4) i++, c = s[i];
			change = true;
		}
		st.push_back(s);
		if(change) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		int i = 0;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(find(ar.begin(), ar.end(), s) != ar.end()){
				if(s[i] == '0') s[i] = '9';
				else s[i] = ((s[i] - '0') - 1) + '0';
				i++, c = s[i];
				continue;
			}
			if(s[i] == c && i < 4) i++, c = s[i];
		}
		st.push_back(s);
	}
	for(int i = 0; i < n; i++){
		if(ar[i] != st[i]) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
const int mod=1000000007;
int i;

int countdigits(int n){
    int c=0;
    while(n!=0){
        c++;
        n=n/10;
    }
    return c;
}

int32_t main(){
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,p,ways=0;
        cin>>n;
        map <int,int> mp;
        set<int> s;
        vector <int> v;
        while(n--){
            cin>>p;
            s.insert(p);
            mp[p]++;
        }
        for(auto x: s){
            ways+=(mp[x]-1);
            for(int i=0;i<mp[x];i++){
                v.pb(x+i);
            }
        }
        cout<<ways<<endl;
        for(auto &x: v){
            if(countdigits(x)!=4){
                for(int i=0;i<4-countdigits(x);i++){
                    cout<<0;
                }
                cout<<x<<endl;
            }
            else{
                cout<<x<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        unordered_map<string,int> h;
        unordered_set<char> used;
        string s[n];
        char c='0';
        for(i=0;i<n;i++){
            cin>>s[i];
            used.insert(s[i][3]);
        }
        for(i=0;i<n;i++){
            if(h.count(s[i])==1){
                used.insert(s[i][3]);
                ways++;
                for(char c='0';c<='9';c++){
                    if(used.count(c)==0){
                        s[i][3]=c;
                        used.insert(c);
                        break;
                    }
                }
            }
            h[s[i]]++;
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
const int mod=1000000007;
int i;

int countdigits(int n){
    int c=0;
    while(n!=0){
        c++;
        n=n/10;
    }
    return c;
}

int32_t main(){
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        string p;
        map <string,int> mp;
        set<string> s;
        vector <string> v;
        while(n--){
            cin>>p;
            s.insert(p);
            mp[p]++;
        }
        for(auto x: s){
            ways+=(mp[x]-1);
            for(int i=0;i<mp[x];i++){
                string r=x.substr(0,3);
                r+=to_string(i);
                v.pb(r);
            }
        }
        cout<<ways<<endl;
        for(auto &x: v){
            cout<<x<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        map<string,int> mp;
        string p,r;
        vector<string> v;
        set<string> s;
        char c;
        for(i=0;i<n;i++){
            cin>>p;
            mp[p]++;
            s.insert(p);
        }
        for(auto &x: s){
            mp[x]--;
            c='0';
            v.pb(x);
            for(int i=0;i<mp[x];i++){
                ways++;
                string r = x;
                r[3]=c;
                v.pb(r);
                c++;
            }
        }
        cout<<ways<<'\n';
        for(auto &x: v){
            cout<<x<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        unordered_map<string,int> h;
        string s[n];
        char c='0';
        for(i=0;i<n;i++){
            cin>>s[i];
            if(h.count(s[i])==1){
                ways++;
                s[i][3]=c;
                c++;
            }
            h[s[i]]++;
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        unordered_map<string,int> h;
        unordered_set<char> used;
        string s[n];
        char c='0';
        for(i=0;i<n;i++){
            cin>>s[i];
            if(h.count(s[i])==1){
                used.insert(s[i][3]);
                ways++;
                for(char c='0';c<='9';c++){
                    if(used.count(c)==0){
                        s[i][3]=c;
                        used.insert(c);
                        break;
                    }
                }
            }
            h[s[i]]++;
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        map<string,int> mp;
        string s[n];
        char c;
        for(i=0;i<n;i++){
            cin>>s[i];
            mp[s[i]]++;
        }
        for(int i=0;i<n;i++){
            c='0';
            if(mp[s[i]]>1){
                mp[s[i]]--;
                for(int j=1;j<=mp[s[i]];j++){
                    ways++;
                    s[j][3]=c;
                    c++;
                    mp[s[j]]--;
                }
            }
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
const int mod=1000000007;
int i;

int countdigits(int n){
    int c=0;
    while(n!=0){
        c++;
        n=n/10;
    }
    return c;
}

int32_t main(){
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        string p;
        map <string,int> mp;
        set<string> s;
        vector <string> v;
        while(n--){
            cin>>p;
            s.insert(p);
            mp[p]++;
        }
        for(auto x: s){
            ways+=(mp[x]-1);
            for(int i=0;i<mp[x];i++){
                if(i>0){
                string r=x.substr(0,3);
                r+=to_string(i);
                v.pb(r);
                }
                else
                v.pb(x);
            }
        }
        cout<<ways<<endl;
        for(auto &x: v){
            cout<<x<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        unordered_map<string,int> h;
        unordered_set<char> used;
        string s[n];
        char c='0';
        for(i=0;i<n;i++){
            cin>>s[i];
            used.insert(s[i][3]);
        }
        for(i=0;i<n;i++){
            if(h.count(s[i])==1){
                used.insert(s[i][3]);
                ways++;
                for(char c='0';c<='9';c++){
                    if(used.count(c)==0){
                        s[i][3]=c;
                        used.insert(c);
                        break;
                    }
                }
            }
            h[s[i]]++;
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
const int mod=1000000007;
int i;

int countdigits(int n){
    int c=0;
    while(n!=0){
        c++;
        n=n/10;
    }
    return c;
}

int32_t main(){
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,p,ways=0;
        cin>>n;
        map <int,int> mp;
        set<int> s;
        vector <int> v;
        while(n--){
            cin>>p;
            s.insert(p);
            mp[p]++;
        }
        for(auto x: s){
            ways+=(mp[x]-1);
            for(int i=0;i<mp[x];i++){
                v.pb(x+i);
            }
        }
        cout<<ways<<endl;
        for(auto &x: v){
            if(countdigits(x)!=4){
                for(int i=0;i<4-countdigits(x);i++){
                    cout<<0;
                }
                cout<<x<<endl;
            }
            else{
                cout<<x<<endl;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 500
#define int long long
const int mod=998244353;

int i,j;

int32_t main() {
    int t;
    cin>>t;
    while(t--){
        int n,ways=0;
        cin>>n;
        unordered_map<string,int> h;
        string s[n];
        char c='0';
        for(i=0;i<n;i++){
            cin>>s[i];
            if(h.count(s[i])==1){
                ways++;
                s[i][3]=c;
                c++;
                if(c=='9')
                c='0';
            }
            h[s[i]]++;
        }
        cout<<ways<<'\n';
        for(int i=0;i<n;i++){
            cout<<s[i]<<'\n';
        }
    }
	return 0;
}


        #pragma GCC optimize(2)
        #pragma GCC optimize(3)
        #include<bits/stdc++.h>
        #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
        #define ll long long
        #define forn(i,n) for (int i = 0; i < int(n); i++)
        #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
        #pragma GCC target("avx,avx2,fma")
        using namespace std;
        //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
          //a.erase(unique(a.begin(),a.end()),a.end());
           //shuffle(a.begin(),a.end(),rnd);
        template <class nmsl> inline void read(nmsl &x)
        {
        	x=0;
        	char ch=getchar(), w=0;
        	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
        	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
        	x=w?-x:x;
        }
        int main()
        {
           Boost();
           ll t;
           cin>>t;
           while(t--){
             int n;
             cin>>n;
             int a[n];int ans[n];
        	 int c=0;int k=0;
             int visited[10000]={0};
             forn(i,n)
             cin>>a[i];
             forn(i,n){
             	if(visited[a[i]]==0)
             	{ans[c++]=a[i];
             	visited[a[i]]=1;
             	}
             	else{
             	    k++;
             	    while(true){
             	        int val=a[i]+1;
             	        if(val%10==0)
             	        val-=10;
             	        if(visited[val]==0){
             	            ans[c++]=val;
             	            visited[val]=1;
             	            break;
             	        }
             	        else{
             	            val++;
             	            if(val%10==0)
             	        val-=10;
             	        }
             	    }
             	}
        	 }

             cout<<k<<"\n";
             for(int i=0;i<n;i++){
             if(ans[i]>=1000)
             cout<<ans[i]<<"\n";
             else
             {
             	int co=0;
             	int du=ans[i];
             	while(du>0){
             		co++;
             		du/=10;
             	}
             	for(int t=0;t<4-co;t++)
             	cout<<"0";
             	cout<<ans[i]<<"\n";
             }
             }
           }
           return 0;
        }


                #pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     int n;
                     cin>>n;
                     int a[n];int ans[n];
                	 int c=0;int k=0;
                     int visited[10000]={0};
                     forn(i,n)
                     cin>>a[i];
                     forn(i,n){
                     	if(visited[a[i]]==0)
                     	{ans[c++]=a[i];
                     	visited[a[i]]=1;
                     	}
                     	else{
                     	    k++;
                     	    int diff=10-(a[i]%10);

                     	    int y=a[i]+visited[a[i]];
                     	    if(visited[a[i]]>=diff)
                     	    y-=10;
                     	    ans[c++]=y;
                     	    visited[a[i]]++;
                     	}
                	 }

                     cout<<k<<"\n";
                     for(int i=0;i<n;i++){
                     if(ans[i]>=1000)
                     cout<<ans[i]<<"\n";
                     else
                     {
                     	int co=0;
                     	int du=ans[i];
                     	while(du>0){
                     		co++;
                     		du/=10;
                     	}
                     	for(int t=0;t<4-co;t++)
                     	cout<<"0";
                     	cout<<ans[i]<<"\n";
                     }
                     }
                   }
                   return 0;
                }


                #pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     int n;
                     cin>>n;
                     int a[n];int ans[n];
                	 int c=0;int k=0;
                     int visited[10000]={0};
                     forn(i,n)
                     cin>>a[i];
                     forn(i,n){
                     	if(visited[a[i]]==0)
                     	{ans[c++]=a[i];
                     	visited[a[i]]=1;
                     	}
                     	else{
                     	    k++;
                     	    int diff=10-(a[i]%10);

                     	    int y=a[i]+visited[a[i]];
                     	    if(visited[a[i]]>=diff)
                     	    y-=10;
                     	    ans[c++]=y;
                     	    visited[a[i]]++;
                     	}
                	 }

                     cout<<k<<"\n";
                     for(int i=0;i<n;i++){
                     if(ans[i]>=1000)
                     cout<<ans[i]<<"\n";
                     else
                     {
                     	int co=0;
                     	int du=ans[i];
                     	while(du>0){
                     		co++;
                     		du/=10;
                     	}
                     	for(int t=0;t<4-co;t++)
                     	cout<<"0";
                     	if(co==0)
                     	cout<<"\n";
                     	else
                     	cout<<ans[i]<<"\n";
                     }
                     }
                   }
                   return 0;
                }


        #pragma GCC optimize(2)
        #pragma GCC optimize(3)
        #include<bits/stdc++.h>
        #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
        #define ll long long
        #define forn(i,n) for (int i = 0; i < int(n); i++)
        #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
        #pragma GCC target("avx,avx2,fma")
        using namespace std;
        //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
          //a.erase(unique(a.begin(),a.end()),a.end());
           //shuffle(a.begin(),a.end(),rnd);
        template <class nmsl> inline void read(nmsl &x)
        {
        	x=0;
        	char ch=getchar(), w=0;
        	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
        	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
        	x=w?-x:x;
        }
        int main()
        {
           Boost();
           ll t;
           cin>>t;
           while(t--){
             int n;
             cin>>n;
             int a[n];
             map<int,int> val;
             forn(i,n){
             	cin>>a[i];
             	val[a[i]]++;
        	 }
        	 int k=0;
        	 int ans[n];int c=0;
        	map<int,int>::iterator it;
        	for(it=val.begin();it!=val.end();++it){
        		if(it->second>1){
        		int m=it->first;
                k+=it->second-1;
        		for(int i=0;i<(it->second);i++){
        			if(m%10==9){
        				ans[c++]=m;
        				m=m-9;
        			}
        			else{
        				ans[c++]=m;
        				m++;
        			}

        		}

        		}
        		else
        		ans[c++]=it->first;
        	}
             cout<<k<<"\n";
             for(int i=0;i<n;i++){
             if(ans[i]>=1000)
             cout<<ans[i]<<"\n";
             else
             {
             	int co=0;
             	int du=ans[i];
             	while(du>0){
             		co++;
             		du/=10;
             	}
             	for(int t=0;t<4-co;t++)
             	cout<<"0";
             	cout<<ans[i]<<"\n";
             }
             }
           }
           return 0;
        }


            #pragma GCC optimize(2)
            #pragma GCC optimize(3)
            #include<bits/stdc++.h>
            #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
            #define ll long long
            #define forn(i,n) for (int i = 0; i < int(n); i++)
            #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
            #pragma GCC target("avx,avx2,fma")
            using namespace std;
            //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
              //a.erase(unique(a.begin(),a.end()),a.end());
               //shuffle(a.begin(),a.end(),rnd);
            template <class nmsl> inline void read(nmsl &x)
            {
            	x=0;
            	char ch=getchar(), w=0;
            	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
            	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
            	x=w?-x:x;
            }
            int main()
            {
               Boost();
               ll t;
               cin>>t;
               while(t--){
                 int n;
                 cin>>n;
                 int a[n];int ans[n];
            	 int c=0;int k=0;
                 int visited[10000]={0};
                 forn(i,n)
                 cin>>a[i];
                 forn(i,n){
                 	if(visited[a[i]]==0)
                 	{ans[c++]=a[i];
                 	visited[a[i]]=1;
                 	}
                 	else{
                 	    k++;
                 	    ans[c]=((a[i]%10+visited[a[i]])+((a[i]/10)*10)-10);
                 	    if(a[i]-ans[c]>=9)
                 	    ans[c]+=10;
                 	    c++;
                 	    visited[a[i]]++;
                 	}
            	 }

                 cout<<k<<"\n";
                 for(int i=0;i<n;i++){
                 if(ans[i]>=1000)
                 cout<<ans[i]<<"\n";
                 else
                 {
                 	int co=0;
                 	int du=ans[i];
                 	while(du>0){
                 		co++;
                 		du/=10;
                 	}
                 	for(int t=0;t<4-co;t++)
                 	cout<<"0";
                 	cout<<ans[i]<<"\n";
                 }
                 }
               }
               return 0;
            }


#pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     string a[11];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++) {
		bool yes=0;
		for(int j=i+1;j<=n;j++) {
			if(a[i]==a[j]) {
				yes=1;
				break;
			}
		}
		if(yes) {
			set<char> used;
			for(int k=1;k<=n;k++)
				used.insert(a[k][0]);
			for(char k='0';k<='9';k++) {
				if(used.find(char(k))==used.end()) {
					ans++;
					a[i][0]=k;
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
	for(int i=1;i<=n;i++) {
		cout<<a[i]<<endl;
	}
                   }
                   return 0;
                }


                #pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     int n;
                     cin>>n;
                     int a[n];int ans[n];
                	 int c=0;int k=0;
                     int visited[10000]={0};
                     forn(i,n)
                     cin>>a[i];
                     forn(i,n){
                     	if(visited[a[i]]==0)
                     	{ans[c++]=a[i];
                     	visited[a[i]]++;
                     	}
                     	else{
                     	    k++;
                     	    int diff=10-(a[i]%10);

                     	    int y=a[i]+visited[a[i]];
                     	    if(visited[a[i]]>=diff)
                     	    y-=10;
                     	    ans[c++]=y;
                     	    visited[a[i]]++;
                     	    visited[y]++;
                     	}
                	 }

                     cout<<k<<"\n";
                     for(int i=0;i<n;i++){
                     if(ans[i]>=1000)
                     cout<<ans[i]<<"\n";
                     else
                     {
                     	int co=0;
                     	int du=ans[i];
                     	while(du>0){
                     		co++;
                     		du/=10;
                     	}
                     	for(int t=0;t<4-co;t++)
                     	cout<<"0";
                     	if(co==0)
                     	cout<<"\n";
                     	else

                     	cout<<ans[i]<<"\n";
                     }
                     }
                   }
                   return 0;
                }


            #pragma GCC optimize(2)
            #pragma GCC optimize(3)
            #include<bits/stdc++.h>
            #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
            #define ll long long
            #define forn(i,n) for (int i = 0; i < int(n); i++)
            #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
            #pragma GCC target("avx,avx2,fma")
            using namespace std;
            //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
              //a.erase(unique(a.begin(),a.end()),a.end());
               //shuffle(a.begin(),a.end(),rnd);
            template <class nmsl> inline void read(nmsl &x)
            {
            	x=0;
            	char ch=getchar(), w=0;
            	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
            	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
            	x=w?-x:x;
            }
            int main()
            {
               Boost();
               ll t;
               cin>>t;
               while(t--){
                 int n;
                 cin>>n;
                 int a[n];int ans[n];
            	 int c=0;int k=0;
                 int visited[10000]={0};
                 forn(i,n)
                 cin>>a[i];
                 forn(i,n){
                 	if(visited[a[i]]==0)
                 	{ans[c++]=a[i];
                 	visited[a[i]]=1;
                 	}
                 	else{
                 	    k++;
                 	    ans[c]=((a[i]%10+visited[a[i]])+((a[i]/10)*10)-10);
                 	    if(a[i]-ans[c]>=10)
                 	    ans[c]+=10;
                 	    c++;
                 	    visited[a[i]]++;
                 	}
            	 }

                 cout<<k<<"\n";
                 for(int i=0;i<n;i++){
                 if(ans[i]>=1000)
                 cout<<ans[i]<<"\n";
                 else
                 {
                 	int co=0;
                 	int du=ans[i];
                 	while(du>0){
                 		co++;
                 		du/=10;
                 	}
                 	for(int t=0;t<4-co;t++)
                 	cout<<"0";
                 	cout<<ans[i]<<"\n";
                 }
                 }
               }
               return 0;
            }


#pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     int n;
                     cin>>n;
                     int a[n];int ans[n];
                	 int c=0;int k=0;
                     int visited[10000]={0};
                     forn(i,n)
                     cin>>a[i];
                     forn(i,n){
                     	if(visited[a[i]]==0)
                     	{
                     	ans[c++]=a[i];
                     	visited[a[i]]++;
                     	}
                     	else{
                     	    k++;
                     	    int val=a[i];
                     	    while(visited[val]!=0){
                     	    	if(val%10==9)
                     	    	val=val-10;
                     	    	val++;
                     	    }
                     	    ans[c++]=val;
                     	    visited[val]=1;
                     	}
                	 }

                     cout<<k<<"\n";
                     for(int i=0;i<n;i++){
                     if(ans[i]>=1000)
                     cout<<ans[i]<<"\n";
                     else
                     {
                     	int co=0;
                     	int du=ans[i];
                     	while(du>0){
                     		co++;
                     		du/=10;
                     	}
                     	for(int t=0;t<4-co;t++)
                     	cout<<"0";
                     	if(co==0)
                     	cout<<"\n";
                     	else

                     	cout<<ans[i]<<"\n";
                     }
                     }
                   }
                   return 0;
                }


                #pragma GCC optimize(2)
                #pragma GCC optimize(3)
                #include<bits/stdc++.h>
                #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
                #define ll long long
                #define forn(i,n) for (int i = 0; i < int(n); i++)
                #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
                #pragma GCC target("avx,avx2,fma")
                using namespace std;
                //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
                  //a.erase(unique(a.begin(),a.end()),a.end());
                   //shuffle(a.begin(),a.end(),rnd);
                template <class nmsl> inline void read(nmsl &x)
                {
                	x=0;
                	char ch=getchar(), w=0;
                	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
                	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
                	x=w?-x:x;
                }
                int main()
                {
                   Boost();
                   ll t;
                   cin>>t;
                   while(t--){
                     int n;
                     cin>>n;
                     int a[n];int ans[n];
                	 int c=0;int k=0;
                     int visited[10000]={0};
                     forn(i,n)
                     cin>>a[i];
                     forn(i,n){
                     	if(visited[a[i]]==0)
                     	{ans[c++]=a[i];
                     	visited[a[i]]=1;
                     	}
                     	else{
                     	    k++;
                     	    int diff=min(a[i]%10,10-(a[i]%10));
                     	    int y=a[i]+visited[a[i]];
                     	    if(visited[a[i]]>=diff)
                     	    y-=10;
                     	    ans[c++]=y;
                     	    visited[a[i]]++;
                     	}
                	 }

                     cout<<k<<"\n";
                     for(int i=0;i<n;i++){
                     if(ans[i]>=1000)
                     cout<<ans[i]<<"\n";
                     else
                     {
                     	int co=0;
                     	int du=ans[i];
                     	while(du>0){
                     		co++;
                     		du/=10;
                     	}
                     	for(int t=0;t<4-co;t++)
                     	cout<<"0";
                     	cout<<ans[i]<<"\n";
                     }
                     }
                   }
                   return 0;
                }


        #pragma GCC optimize(2)
        #pragma GCC optimize(3)
        #include<bits/stdc++.h>
        #define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// or cin.tie(NULL);
        #define ll long long
        #define forn(i,n) for (int i = 0; i < int(n); i++)
        #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
        #pragma GCC target("avx,avx2,fma")
        using namespace std;
        //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
          //a.erase(unique(a.begin(),a.end()),a.end());
           //shuffle(a.begin(),a.end(),rnd);
        template <class nmsl> inline void read(nmsl &x)
        {
        	x=0;
        	char ch=getchar(), w=0;
        	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
        	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
        	x=w?-x:x;
        }
        int main()
        {
           Boost();
           ll t;
           cin>>t;
           while(t--){
             int n;
             cin>>n;
             int a[n];int ans[n];
        	 int c=0;int k=0;
             int visited[10000]={0};
             forn(i,n)
             cin>>a[i];
             forn(i,n){
             	if(visited[a[i]]==0)
             	{ans[c++]=a[i];
             	visited[a[i]]=1;
             	}
             	else{
             	    k++;
             	    ans[c++]=((a[i]%10+visited[a[i]])+((a[i]/10)*10)-10);
             	    visited[a[i]]++;
             	}
        	 }

             cout<<k<<"\n";
             for(int i=0;i<n;i++){
             if(ans[i]>=1000)
             cout<<ans[i]<<"\n";
             else
             {
             	int co=0;
             	int du=ans[i];
             	while(du>0){
             		co++;
             		du/=10;
             	}
             	for(int t=0;t<4-co;t++)
             	cout<<"0";
             	cout<<ans[i]<<"\n";
             }
             }
           }
           return 0;
        }


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

struct node {
	int x;
	node() {}
	node(int x) {
		this->x = x;
	}
	bool operator<(const node& oth)const {
		return x > oth.x;
	}
};
map<node, int>MAP;

int32_t main()
{
	  //freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				while (MAP.count( node(it.first.x + k)  ))k++;
				MAP[ node(it.first.x + k) ] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it=MAP.begin();it!=MAP.end();it++)
		{
			printf("%04d", it->first);
			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

map<int, int>MAP;

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}
int32_t main()
{
	    freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		vector<int>v;
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
			v.push_back(x);
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				//int rx = rand() % 9999;
				while (MAP.count( it.first + k )|| !check(it.first,it.first+k)  )k++;
				MAP[ it.first + k ] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it:v)
		{
			for (auto i : MAP)
			{
				if (check(it, i.first) || it==i.first)

				{
					printf("%04d", i.first);
					MAP.erase(i.first);
					break;
				}

			}

			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];
int cnt[100000];
set<int>s;

int next_int(int x) {
	return (x + 1) % 10000;
}

int32_t main()
{
	//     freopen("1.in","r",stdin);
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		vector<int>ans;
		CLR(cnt);
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);
			cnt[a[i]]++;
		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(cnt[a[i]]==1)ans.push_back(a[i]);
			else
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x, a[i])))x = next_int(x);
				cnt[a[i]]--;
				s.insert(x);
				cnt[x] = 1;
				c++;
				ans.push_back(x);
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];

multiset<int>s;

int next_int(int x) {
	return (x + 1) % 10000;
}
vector<int>ans;
int32_t main()
{
	//    freopen("1.in","r",stdin);
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		ans.clear();
		s.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);

		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(s.count(a[i])==1)ans.push_back(a[i]);
			else
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x, a[i])))x = next_int(x);

				s.erase(s.find(a[i]));

				s.insert(x);
				c++;
				ans.push_back(x);
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

map<int, int>MAP;

int32_t main()
{
	  //freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				while (MAP.count(it.first + k))k++;
				MAP[it.first + k] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it=MAP.begin();it!=MAP.end();it++)
		{
			printf("%04d", it->first);
			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

struct node {
	int x;
	node() {}
	node(int x) {
		this->x = x;
	}
	bool operator<(const node& oth)const {
		return x > oth.x;
	}
};
map<node, int>MAP;

int32_t main()
{
	  //freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				while (MAP.count( node(it.first.x + k)  ))k--;
				MAP[ node(it.first.x + k) ] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it=MAP.begin();it!=MAP.end();it++)
		{
			printf("%04d", it->first);
			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];

multiset<int>s;

vector<int>ans;
int32_t main()
{
	  //  freopen("1.in","r",stdin);
	srand(time(0));
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		ans.clear();
		s.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);
		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(s.count(a[i])==1)ans.push_back(a[i]);
			else
			{
				char sint[10];
				char temp[10];
				sprintf(sint, "%d", a[i]);
				int f = 0;
				for (int j = 0; j < 4; j++)
				{
					if (f)break;
					for (int k = 0; k <= 9; k++)
					{
						 strcpy(temp,sint);
						 temp[j] = k + '0';
						 int x =  atoi(temp);
						 if(s.count(x))continue;
						 s.erase(s.find(a[i]));
						 s.insert(x);
						 c++;
						 ans.push_back(x);
						 f = 1;
						 break;
					}
				}

			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

map<int, int>MAP;

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}
int32_t main()
{
	   // freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		vector<int>v;
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
			v.push_back(x);
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				//int rx = rand() % 9999;
				while (MAP.count( (it.first + k)%10000 )|| !check(it.first, (it.first + k) % 10000)  )k++;
				MAP[(it.first + k) % 10000] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it:v)
		{
			for (auto i : MAP)
			{
				if (check(it, i.first) || it==i.first)

				{
					printf("%04d", i.first);
					MAP.erase(i.first);
					break;
				}

			}

			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];

multiset<int>s;

int next_int(int x) {
	return (x + 1) % 10000;
}

int32_t main()
{
	//    freopen("1.in","r",stdin);
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		vector<int>ans;

		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);

		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(s.count(a[i])==1)ans.push_back(a[i]);
			else
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x, a[i])))x = next_int(x);

				s.erase(s.find(a[i]));

				s.insert(x);
				c++;
				ans.push_back(x);
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];
int cnt[100000];
set<int>s;

int next_int(int x) {
	return (x + 1) % 10000;
}

int32_t main()
{
	    //  freopen("1.in","r",stdin);
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		vector<int>ans;
		CLR(cnt);
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);
			cnt[a[i]]++;
		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(cnt[a[i]]==1)ans.push_back(a[i]);
			else while (cnt[a[i]] > 1)
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x,a[i]))  )x = next_int(x);
				cnt[a[i]]--;
				ans.push_back(x);
				s.insert(x);
				cnt[x] = 1;
				c++;
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];

multiset<int>s;

int next_int(int x) {
	return rand() % 10000;
}
vector<int>ans;
int32_t main()
{
	//    freopen("1.in","r",stdin);
	srand(time(0));
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		ans.clear();
		s.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);
		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(s.count(a[i])==1)ans.push_back(a[i]);
			else
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x, a[i])))x = next_int(x);
				s.erase(s.find(a[i]));
				s.insert(x);
				c++;
				ans.push_back(x);
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}

int a[100];
int cnt[100000];
set<int>s;

int next_int(int x) {
	return (x + 1) % 10000;
}

int32_t main()
{
	     freopen("1.in","r",stdin);
	int t;
	in(t);
	//int k = 0;
	while (t--)
	{
		vector<int>ans;
		CLR(cnt);
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			in(a[i]);
			s.insert(a[i]);
			cnt[a[i]]++;
		}
		int c = 0;
		for (int i = 0; i < n; i++)
		{
			if(cnt[a[i]]==1)ans.push_back(a[i]);
			else
			{
				int x = next_int(a[i]);
				while (s.count(x) || (!check(x, a[i])))x = next_int(x);
				cnt[a[i]]--;
				s.insert(x);
				cnt[x] = 1;
				c++;
				ans.push_back(x);
			}
		}
		print(c);
		for (auto it : ans)
		{
			printf("%04d\n", it);
		}

	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

map<int, int>MAP;

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}
int32_t main()
{
	    //freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		vector<int>v;
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
			v.push_back(x);
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				//int rx = rand() % 9999;
				while (MAP.count( (it.first + k)%10000 )|| !check(it.first, (it.first + k) % 10000)  )k++;
				MAP[(it.first + k) % 10000] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it:v)
		{
			bool f = 0;
			for (auto i : MAP)
			{
				if (it == i.first)

				{
					printf("%04d", i.first);
					MAP.erase(i.first);
					f = 1;
					break;
				}

			}

			if (!f)
			{
				for (auto i : MAP)
				{
					if (check(it, i.first))
					{
						printf("%04d", i.first);
						MAP.erase(i.first);
						break;
					}
				}
			}

			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
#include <ctime>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
#define _all(v) (v).begin(),(v).end()
#define _endl putchar('\n')
#define _space putchar(' ')
const int32_t Accepted = 0;
template<typename T>void in(T& x) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; }
template<typename T, typename... Types>void in(T& x, Types& ... oth) { static char ch; static bool neg; for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar()); for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar()); x = neg ? -x : x; in(oth...); }
template<typename T>T _pow_mod(T a, T b, T mod) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base) % mod; base = (base * base) % mod; b >>= 1; }return res; }
template<typename T>T _pow(T a, T b) { T base = a, res = 1; while (b) { if (b & 1)res = (res * base); base = (base * base); b >>= 1; }return res; }
template<typename T>void out(T x) { char s[65]; int32_t cnt = 0; if (x > 0)while (x > 0)s[cnt++] = (x - (x / 10 * 10)) + '0', x /= 10; else if (x < 0) { while (x < 0)s[cnt++] = (x / 10 * 10) - x + '0', x /= 10; s[cnt++] = '-'; }if (cnt == 0)putchar('0'); else for (int32_t i = cnt - 1; ~i; i--)putchar(s[i]); }
template<typename T>void print(T x) { out(x); _endl; }
template<typename T, typename... types >void print(T x, types... oth) { out(x); _space; print(oth...); }
typedef long long ll;
//mt19937_64 _r(random_device{}());
const int32_t MAXN = 1e6 + 5;
//------------------------Azir----------------------------
/*
Если жизнь тебя обманет,
Не печалься，не сердись!
В день уныния смирись:
День веселья, верь, настанет.
Сердце в будущем живёт;
Настоящее уныло:
Все мгновенно，все пройдёт;
Что пройдёт, то будет мило.
KOBVCS
*/

map<int, int>MAP;

bool check(int a, int b)//只有一个数位 不一样
{
	char sa[6], sb[6];
	sprintf(sa, "%d", a);
	sprintf(sb, "%d", b);
	int c = 0;
	for (int i = 0; i < 4; i++)
	{
		if (sa[i] != sb[i])c++;
	}
	return c == 1;
}
int32_t main()
{
	   // freopen("1.in","r",stdin);
	int t;
	in(t);
	while (t--)
	{
		MAP.clear();
		int n;
		in(n);
		for (int i = 0; i < n; i++)
		{
			int x;
			in(x);
			MAP[x]++;
		}
		int cnt = 0;
		for (auto it : MAP) {
			int k = 1;
			while (it.second > 1)
			{
				cnt++;
				//int rx = rand() % 9999;
				while (MAP.count( it.first + k )|| !check(it.first,it.first+k)  )k++;
				MAP[ it.first + k ] = 1;
				it.second--;
			}
		}
		print(cnt);
		int f = 0;
		for (auto it=MAP.begin();it!=MAP.end();it++)
		{
			printf("%04d", it->first);
			//f++ == n - 1 ? _endl : _space;
			_endl;
		}
	}

	return Accepted;
}


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0;
      char ch='a';      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][0]=ch;
                   ch++;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          //cout<<s[1][0];
          s[100][100]={};
    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0;
      char ch='a';      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][0]=ch;
                   ch++;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          //cout<<s[1][0];
          //s[100][100]={};
    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=0,d=0,e=0;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   if(s[j][e]=='0'+f)
                    f++;
                   s[j][e]='0'+f;
                   f++;
                   d++;
                   if(d>8)
                   {
                       e++;
                       d=0;
                   }
                   if(f>9)
                    f=0;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0,f=0,d=0,e=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              for(j=0;j<4;j++)
              {
                  cout<<s[i][j];
              }
              cout<<endl;

          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=0,z=0,c=0,g;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;

                   z++;
                   c=ceil(z/(4*1.0));
                   for(g=0;g<c;g++)
                   {
                       s[j][f]='0';
                       f++;
                   }
                   if(f>3)
                    f=0;

               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          z=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              for(j=0;j<4;j++)
              {
                  cout<<s[i][j];
              }
              cout<<endl;

          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=0;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][f]='5';
                   f++;
                   if(f>3)
                    f=0;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              for(j=0;j<4;j++)
              {
                  cout<<s[i][j];
              }
              cout<<endl;

          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/