#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  cin >> tt;
  while (tt--) {
    long long n, i, j;
    cin >> n;
    map<char, bool> ok;
    string str[n + 1];
    vector<string> vs;
    set<string> s;
    for (i = 0; i < n; i++) {
      cin >> str[i];
      ok[str[i][3]] = true;
      s.insert(str[i]);
    }
    vs.push_back(str[0]);
    cout << n - s.size() << '\n';
    char ch = '0';
    for (i = 1; i < n; i++) {
      while (count(vs.begin(), vs.end(), str[i])) {
        if (!ok[ch]) {
          str[i][3] = ch;
          ok[ch] = true;
        }
        ch++;
      }
      vs.push_back(str[i]);
      j = i - 1;
    }
    for (i = 0; i < n; i++) cout << str[i] << '\n';
  }
  cerr << " Execution : " << (1.0 * clock()) / CLOCKS_PER_SEC << "s \n";
  return 0;
}
