#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<string, long long int> mp;
    string ar[n];
    for (int i = 0; i < n; i++) {
      string item;
      cin >> item;
      ar[i] = item;
      mp[item]++;
    }
    long long int finalans = 0;
    for (auto s : mp) {
      finalans = finalans + min(0LL, s.second - 1);
    }
    vector<string> ansstring;
    unordered_set<string> s;
    for (int i = 0; i < n; i++) {
      if (mp[ar[i]] == 1) {
        s.insert(ar[i]);
        ansstring.push_back(ar[i]);
      } else {
        if (s.find(ar[i]) == s.end()) {
          s.insert(ar[i]);
          ansstring.push_back(ar[i]);
        } else {
          finalans++;
          string str = ar[i], temp = ar[i];
          bool flag = false;
          for (int i = 0; i < 4 && flag == false; i++) {
            for (int j = 0; j <= 9 && flag == false; j++) {
              str[i] = '0' + j;
              if (s.find(str) == s.end() && mp.find(str) == mp.end()) {
                s.insert(str);
                ansstring.push_back(str);
                flag = true;
              }
            }
            str = temp;
          }
        }
      }
    }
    cout << finalans << endl;
    for (auto itr : ansstring) cout << itr << endl;
  }
  return 0;
}
