#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<string> a(n);
    map<string, int> cnt;
    map<string, set<int>> notFree;
    int x = 0;
    for (auto& s : a) {
      cin >> s;
      string t = s;
      t.pop_back();
      notFree[t].insert(s[3] - '0');
      cnt[s]++;
      if (cnt[s] > 1) x++;
    }
    cout << x << '\n';
    for (auto& s : a) {
      string t = s;
      t.pop_back();
      if (cnt[s] > 1) {
        cnt[s]--;
        for (int d = 0; d < 10; d++) {
          if (notFree[t].count(d) == 0) {
            s[3] = char(d + '0');
            notFree[t].insert(d);
            break;
          }
        }
      }
      cout << s << '\n';
    }
  }
  return 0;
}
