#include <bits/stdc++.h>
using namespace std;
void swap(long long &a, long long &b) {
  auto tm = a;
  a = b;
  b = tm;
}
const long long mod = 1000000009;
const long long mod2 = 998244353;
const long long INF = (1LL << 50) - 1;
const long long N = 1e6 + 25;
void bheja_fry() {
  long long n;
  cin >> n;
  string s[n];
  map<string, vector<pair<char, long long>>> m;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    cin >> s[i];
    string t;
    for (long long(j) = (0); (j) < (3); ++(j)) t.push_back(s[i][j]);
    m[t].push_back({s[i][3], i});
  }
  long long ct = 0;
  vector<pair<long long, string>> ans;
  for (auto &(j) : (m)) {
    vector<char> a;
    vector<long long> b;
    set<char> st;
    for (char ch = '0'; ch <= '9'; ++ch) st.insert(ch);
    for (auto &(i) : (j.second)) {
      if (st.find(i.first) != st.end()) {
        st.erase(i.first);
        string t;
        t = j.first;
        t.push_back(i.first);
        ans.push_back({i.second, t});
      } else
        b.push_back(i.second);
    }
    ct += (long long)(b).size();
    for (auto &(i) : (b)) {
      string t = j.first;
      t.push_back(*st.begin());
      st.erase(st.begin());
      ans.push_back({i, t});
    }
  }
  cout << ct << "\n";
  sort((ans).begin(), (ans).end());
  for (auto &(i) : (ans)) cout << i.second << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  for (long long(i) = (1); (i) < (t + 1); ++(i)) {
    bheja_fry();
  }
  return 0;
}
