#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s[n];
    map<string, int> m;
    set<string> k;
    int count = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      k.insert(s[i]);
    }
    for (int i = 0; i < n; i++) {
      if (m[s[i]] >= 1) {
        count++;
        int j = 0;
        while (k.find(s[i]) != k.end()) {
          s[i][3] = j + '0';
          j++;
        }
      }
      m[s[i]]++;
      k.insert(s[i]);
    }
    cout << count << endl;
    for (int i = 0; i < n; i++) cout << s[i] << endl;
  }
  return 0;
}
