#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, ans = 0;
    scanf("%d", &n);
    map<string, int> book;
    vector<string> aa, temp;
    for (int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      book[s] = 1;
      temp.push_back(s);
    }
    for (vector<string>::iterator it = temp.begin(); it < temp.end(); it++) {
      string s;
      s = *it;
      if (book[s] == 1) {
        book[s]++;
        aa.push_back(s);
      } else {
        for (int i = 0; i <= 9; i++) {
          s[3] = i + '0';
          if (!book.count(s)) {
            book[s] = 1;
            aa.push_back(s);
            break;
          }
        }
        ans++;
      }
    }
    printf("%d\n", ans);
    for (vector<string>::iterator it = aa.begin(); it < aa.end(); it++)
      cout << *it << endl;
  }
}
