#include <bits/stdc++.h>
using namespace std;
void operate() {
  int nc;
  int changes = 0;
  cin >> nc;
  map<string, set<int> > found;
  map<int, string> ready;
  vector<pair<string, int> > waiting;
  for (int i = 0; i < nc; i++) {
    string a;
    cin >> a;
    string little = a.substr(1, 3);
    stringstream ss;
    ss << string(1, a[0]);
    int start;
    ss >> start;
    if (found.count(little)) {
      if (!found[little].count(start)) {
        found[little].insert(start);
        ready[i] = a;
      } else {
        changes += 1;
        waiting.push_back(make_pair(little, i));
      }
    } else {
      found[little].insert(start);
      ready[i] = a;
    }
  }
  for (int i = 0; i < changes; i++) {
    for (int x = 0; x < 10; x++) {
      pair<string, int> give = waiting[i];
      if (!found[give.first].count(x)) {
        stringstream ss;
        ss << x;
        string b;
        ss >> b;
        found[give.first].insert(x);
        ready[give.second] = b + give.first;
        break;
      }
    }
  }
  cout << changes << endl;
  for (int i = 0; i < nc; i++) cout << ready[i] << endl;
}
int main() {
  int tests;
  cin >> tests;
  for (int i = 0; i < tests; i++) operate();
  return 0;
}
