#include <bits/stdc++.h>
#pragma GCC optimize("O2")
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    map<string, int> mp, mpp;
    for (string s : v) mp[s]++;
    int cnt = 0;
    for (auto &k : mp) {
      if (k.second == 1) continue;
      while (k.second > 1) {
        k.second--;
        cnt++;
        bool can = 0;
        for (int i = 0; i < 4 && !can; i++) {
          string ss = k.first;
          for (int j = '0'; j <= '9' && !can; j++) {
            ss[i] = j;
            if (mp.find(ss) == mp.end() && mpp.find(ss) == mpp.end()) {
              can = 1;
              mpp[ss] = 1;
              for (int id = 0; id < n; id++)
                if (v[id] == k.first) {
                  v[id] = ss;
                  break;
                }
            }
          }
        }
      }
    }
    cout << cnt << '\n';
    for (int i = 0; i < n; i++) cout << v[i] << '\n';
  }
  return 0;
}
