#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    map<long long, long long> mp;
    map<long long, long long> vis;
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
      mp[arr[i]]++;
    }
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      if (vis[arr[i]] == 0) {
        vis[arr[i]]++;
        continue;
      } else {
        long long shit = arr[i];
        for (long long j = 0; j < 10; j++) {
          shit %= 1000;
          shit = j * 1000 + shit;
          if (mp[shit] == 0) {
            mp[shit] = 1;
            break;
          }
        }
        arr[i] = shit;
        sum++;
      }
    }
    cout << sum << endl;
    for (long long i = 0; i < n; i++) {
      long long shit = arr[i];
      long long dig = 0;
      while (shit) {
        dig++;
        shit = shit / 10;
      }
      dig = 4 - dig;
      while (dig--) cout << 0;
      if (arr[i])
        cout << arr[i] << " ";
      else
        cout << " ";
    }
    cout << endl;
  }
}
