#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, ans;
  string s;
  cin >> t;
  map<string, vector<int>> c;
  set<string> u;
  vector<string> values(10);
  for (int i = 0; i < t; i++) {
    cin >> n;
    ans = 0;
    c.clear();
    values.clear();
    u.clear();
    for (int j = 0; j < n; j++) {
      cin >> s;
      u.insert(s);
      auto it = c.find(s);
      if (it != c.end()) {
        vector<int> v = it->second;
        v.push_back(j);
        c[s] = v;
      } else {
        c[s] = {j};
      }
    }
    for (auto it = c.begin(); it != c.end(); it++) {
      auto a = it->second;
      values[a[0]] = it->first;
      if (a.size() > 1) {
        for (int k = 1; k < a.size(); k++) {
          ans++;
          string v = it->first;
          for (char r = '0'; r <= '9'; r++) {
            v[0] = r;
            if (u.find(v) == u.end()) {
              u.insert(v);
              values[a[k]] = v;
              break;
            }
          }
        }
      }
    }
    cout << ans << endl;
    for (int j = 0; j < n; j++) {
      cout << values[j] << endl;
    }
  }
}
