#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int ans[N];
int arr[N];
int n;

int vis[N];
vec <int> con;

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
}

int calc(int k) {
    int dif = 0;
    int res = 1;
    fill(vis, vis + N, 0);
    for(int i = 1; i <= n; ++i) {
        if(vis[arr[i]] < res) {
            vis[arr[i]] = res;
            if(++dif > k) {
                dif = 1;
                res++;
            }
        }
    }
    return res;
}

int bin_search(int l, int r, int k) {
    if(l == r) {
        return l;
    }
    int q = l + r + 1 >> 1;
    if(calc(q) == k) {
        return bin_search(q, r, k);
    } else {
        return bin_search(l, q - 1, k);
    }
}

void solve() {
    fill(ans, ans + N, inf);
    for(int i = 1; i <= n; ) {
        int k = calc(i);
        int q = bin_search(i, n, k);
        ans[i] = k;
        i = q + 1;
    }
    for(int i = 1; i <= n; ++i) {
        ans[i] = min(ans[i], ans[i - 1]);
        cout << ans[i] << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int ans[N];
int arr[N];
int n;

bool vis[N];
vec <int> con;

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
}

int calc(int k) {
    int dif = 0;
    int res = 1;
    fill(vis, vis + N, 0);
    for(int i = 1; i <= n; ++i) {
        if(!vis[arr[i]]) {
            vis[arr[i]] = 1;
            if(++dif > k) {
                for(int e: con) {
                    vis[e] = 0;
                }
                con.clear();
                dif = 1;
                res++;
            }
            con.pb(arr[i]);
        }
    }
    return res;
}

int bin_search(int l, int r, int k) {
    if(l == r) {
        return l;
    }
    int q = l + r + 1 >> 1;
    if(calc(q) == k) {
        return bin_search(q, r, k);
    } else {
        return bin_search(l, q - 1, k);
    }
}

void solve() {
    fill(ans, ans + N, inf);
    for(int i = 1; i <= n; ) {
        int k = calc(i);
        int q = bin_search(i, n, k);
        ans[i] = k;
        i = q + 1;
    }
    for(int i = 1; i <= n; ++i) {
        ans[i] = min(ans[i], ans[i - 1]);
        cout << ans[i] << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int ans[N];
int arr[N];
int n;

int vis[N];
vec <int> con;

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
}

int calc(int k) {
    int dif = 0;
    int res = 1;
    fill(vis, vis + N, 0);
    for(int i = 1; i <= n; ++i) {
        if(vis[arr[i]] < res) {
            if(++dif > k) {
                dif = 1;
                res++;
            }
            vis[arr[i]] = res;
        }
    }
    return res;
}

int bin_search(int l, int r, int k) {
    if(l == r) {
        return l;
    }
    int q = l + r + 1 >> 1;
    if(calc(q) == k) {
        return bin_search(q, r, k);
    } else {
        return bin_search(l, q - 1, k);
    }
}

void solve() {
    fill(ans, ans + N, inf);
    for(int i = 1; i <= n; ) {
        int k = calc(i);
        int q = bin_search(i, n, k);
        ans[i] = k;
        i = q + 1;
    }
    for(int i = 1; i <= n; ++i) {
        ans[i] = min(ans[i], ans[i - 1]);
        cout << ans[i] << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 3;
const int maxN = 3e6 + 1;
int n, cur;

int pre[N];
int arr[N];
int lst[N];
int upd[N];
int root[N];

struct Node {
    int l, r;
    int L, R;
    int cnt;
} node[maxN];

int build(int l, int r) {
    int id = ++cur;
    node[id].l = l;
    node[id].r = r;
    if(l == r) {
        node[id].cnt = !pre[l];
        return id;
    }
    int q = l + r >> 1;
    node[id].L = build(l, q);
    node[id].R = build(q + 1, r);
    node[id].cnt = node[node[id].L].cnt + node[node[id].R].cnt;
    return id;
}

int update(int p, int i) {
    int id = ++cur;
    node[id].l = node[p].l;
    node[id].r = node[p].r;
    if(node[id].l == node[id].r) {
        node[id].cnt = 1;
        return id;
    }
    int q = node[id].l + node[id].r >> 1;
    if(i <= q) {
        node[id].L = update(node[p].L, i);
        node[id].R = node[p].R;
    } else {
        node[id].L = node[p].L;
        node[id].R = update(node[p].R, i);
    }
    node[id].cnt = node[node[id].L].cnt + node[node[id].R].cnt;
    return id;
}

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    for(int i = 1; i <= n; ++i) {
        pre[i] = lst[arr[i]];
        lst[arr[i]] = i;
        upd[pre[i]] = i;
    }
}

int query(int x, int l, int r) {
    if(node[x].l == l && node[x].r == r) {
        return node[x].cnt;
    }
    int res = 0;
    int q = node[x].l + node[x].r >> 1;
    if(l <= q) {
        res += query(node[x].L, l, min(q, r));
    }
    if(r > q) {
        res += query(node[x].R, max(q + 1, l), r);
    }
    return res;
}

int find(int x, int k) {
    if(node[x].l == node[x].r) {
        return node[x].l;
    }
    int d = node[node[x].L].cnt;
    if(k < d) {
        return find(node[x].L, k);
    } else {
        return find(node[x].R, k - d);
    }
}

void solve() {
    root[0] = build(0, n + 1);
    for(int i = 1; i <= n; ++i) {
        if(upd[i]) {
            root[i] = update(root[i - 1], upd[i]);
        } else {
            root[i] = root[i - 1];
        }
    }
    for(int i = 1; i <= n; ++i) {
        int cnt = 0;
        for(int cur = 1; cur <= n; ) {
            int p = query(root[cur - 1], 0, cur - 1);
            cur = find(root[cur - 1], p + i);
            cnt++;
        }
        cout << cnt << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 3;
const int maxN = 3e6 + 1;
int n, cur;

int pre[N];
int arr[N];
int lst[N];
int upd[N];
int root[N];

struct Node {
    int l, r;
    int L, R;
    int cnt;
} node[maxN];

int build(int l, int r) {
    int id = ++cur;
    node[id].l = l;
    node[id].r = r;
    if(l == r) {
        node[id].cnt = !pre[l];
        return id;
    }
    int q = l + r >> 1;
    node[id].L = build(l, q);
    node[id].R = build(q + 1, r);
    node[id].cnt = node[node[id].L].cnt + node[node[id].R].cnt;
    return id;
}

int update(int p, int i) {
    int id = ++cur;
    node[id].l = node[p].l;
    node[id].r = node[p].r;
    if(node[id].l == node[id].r) {
        node[id].cnt = 1;
        return id;
    }
    int q = node[id].l + node[id].r >> 1;
    if(i <= q) {
        node[id].L = update(node[p].L, i);
        node[id].R = node[p].R;
    } else {
        node[id].L = node[p].L;
        node[id].R = update(node[p].R, i);
    }
    node[id].cnt = node[node[id].L].cnt + node[node[id].R].cnt;
    return id;
}

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    for(int i = 1; i <= n; ++i) {
        pre[i] = lst[arr[i]];
        lst[arr[i]] = i;
        upd[pre[i]] = i;
    }
}

int query(int x, int y, int l, int r) {
    if(node[y].l == l && node[y].r == r) {
        return node[y].cnt - node[x].cnt;
    }
    int res = 0;
    int q = node[y].l + node[y].r >> 1;
    if(l <= q) {
        res += query(node[x].L, node[y].L, l, min(q, r));
    }
    if(r > q) {
        res += query(node[x].R, node[y].R, max(q + 1, l), r);
    }
    return res;
}

int find(int x, int y, int k) {
    if(node[y].l == node[y].r) {
        return node[y].l;
    }
    int d = node[node[y].L].cnt - node[node[x].L].cnt;
    if(k < d) {
        return find(node[x].L, node[y].L, k);
    } else {
        return find(node[x].R, node[y].R, k - d);
    }
}

void solve() {
    root[0] = build(0, n + 1);
    for(int i = 1; i <= n; ++i) {
        if(upd[i]) {
            root[i] = update(root[i - 1], upd[i]);
        } else {
            root[i] = root[i - 1];
        }
    }
    for(int i = 1; i <= n; ++i) {
        int cnt = 0;
        for(int cur = 1; cur <= n; ) {
            int p = query(0, root[cur - 1], 0, cur - 1);
            cur = find(0, root[cur - 1], p + i);
            cnt++;
        }
        cout << cnt << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int ans[N];
int arr[N];
int n;

int vis[N];
vec <int> con;

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
}

int calc(int k) {
    int dif = 0;
    int res = 1;
    fill(vis, vis + N, 0);
    for(int i = 1; i <= n; ++i) {
        if(vis[arr[i]] < res) {
            if(++dif > k) {
                dif = 1;
                res++;
            }
            vis[arr[i]] = res;
        }
    }
    return res;
}

void divide_and_conquer(int l, int r) {
    if(l > r) {
        return;
    }
    int xl = calc(l);
    int xr = calc(r);
    if(xl == xr) {
        for(int i = l; i <= r; ++i) {
            ans[i] = xl;
        }
        return;
    }
    int q = l + r >> 1;
    divide_and_conquer(l, q);
    divide_and_conquer(q + 1, r);
}

int bin_search(int l, int r, int k) {
    if(l == r) {
        return l;
    }
    int q = l + r + 1 >> 1;
    if(calc(q) == k) {
        return bin_search(q, r, k);
    } else {
        return bin_search(l, q - 1, k);
    }
}

void solve() {
    // fill(ans, ans + N, inf);
    divide_and_conquer(1, n);
    // for(int i = 1; i <= n; ) {
    //     int k = calc(i);
    //     int q = bin_search(i, n, k);
    //     ans[i] = k;
    //     i = q + 1;
    // }
    for(int i = 1; i <= n; ++i) {
        // ans[i] = min(ans[i], ans[i - 1]);
        cout << ans[i] << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#define NguyenDangQuan the_author
#define my_heart love_you_to_the_moon_and_back

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

bool typetest;
inline void fastIOfileinput()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	typetest = 0;
}

const int N = 1e5 + 5;
int n, a[N];
int ans[N], last[N];

void Read()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
}

int Cal(int k)
{
	int ans = 0;
	memset(last, 0, sizeof last);
	for (int i = 1; i <= n; ++i)
	{
		int j = i, cnt = 0;
		++ans;
		while (j <= n && cnt <= k)
		{
			if (last[a[j]] < i)
				++cnt;
			if (cnt > k)
				break;
			last[a[j]] = j;
			++j;
		}
		i = j - 1;
	}
	return ans;
}

void Recursive(int l, int r, int optr, int optl)
{
	if (l >= r)
		return;
	if (optl == optr)
	{
		for (; l <= r; ++l)
			ans[l] = optl;
		return;
	}
	int mid = (l + r) / 2;
	ans[mid] = Cal(mid);
	Recursive(l, mid, optr, ans[mid]);
	Recursive(mid + 1, r, ans[mid], optl);
}

void Solve()
{
	//cout << Cal(1) << "\n";
	Recursive(1, n, n, 1);
	for (int i = 1; i <= n; ++i)
		cout << ans[i] << " ";
}

int32_t main()
{
	fastIOfileinput();
	if (typetest)

	{
		int t;
		cin >> t;
		while (t--)
		{
			Read();
			Solve();
		}
	}
	else
	{
		Read();
		Solve();
	}
}


#define NguyenDangQuan the_author
#define my_heart love_you_to_the_moon_and_back

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

bool typetest;
inline void fastIOfileinput()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	typetest = 0;
}

const int N = 1e5 + 5;
int n, a[N];
int ans[N], last[N];

void Read()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
}

int Cal(int k)
{
	int ans = 0;
	memset(last, 0, sizeof last);
	for (int i = 1; i <= n; ++i)
	{
		int j = i, cnt = 0;
		++ans;
		while (j <= n && cnt <= k)
		{
			if (last[a[j]] < i)
				++cnt;
			if (cnt > k)
				break;
			last[a[j]] = j;
			++j;
		}
		i = j - 1;
	}
	return ans;
}

void Recursive(int l, int r, int optr, int optl)
{
	if (l >= r)
		return;
	if (optl == optr)
	{
		for (; l <= r; ++l)
			ans[l] = optl;
		return;
	}
	int mid = (l + r) / 2;
	ans[mid] = Cal(mid);
	Recursive(l, mid, optr, ans[mid]);
	Recursive(mid + 1, r, ans[mid], optl);
}

void Solve()
{
	//cout << Cal(1) << "\n";
	ans[n] = 1;
	Recursive(1, n, n, 1);
	for (int i = 1; i <= n; ++i)
		cout << ans[i] << " ";
}

int32_t main()
{
	fastIOfileinput();
	if (typetest)

	{
		int t;
		cin >> t;
		while (t--)
		{
			Read();
			Solve();
		}
	}
	else
	{
		Read();
		Solve();
	}
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

struct Counter:std::unordered_map<int,int>{
	void inc(int x){
		++(*this)[x];
	}
	void dec(int x){
		auto iter=this->find(x);
		if(0==--iter->second)
			this->erase(iter);
	}
};

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;
	std::vector<int> a(n);
	for(int& x:a)std::cin>>x;
	int const old_n=n;
	n=-1;
	a.erase(std::unique(begin(a),end(a)),end(a));

	struct Range:Counter{
		int l,r;
		Range():Counter(),l(0),r(0){};
	};

	std::vector<Range> t(a.size());
	for(unsigned i=0;i<a.size();++i){
		t[i].l=i;
		t[i].r=i+1;
		t[i].inc(a[i]);
	}
	for(int i=1;;){
		std::cout<<t.size()<<' ';
		if(i==old_n)
			break;

		++i;
		for(unsigned j=0;;++j){
			auto& x=t[j];
			while(true){
				if(x.r==(int)a.size()){
					t.erase(begin(t)+j+1,end(t)); // invalidates x
					goto break_outer;
				}
				if((int)x.size()==i&&x.find(a[x.r])==end(x))
					break;
				x.inc(a[x.r++]);
			}

			auto& y=t[j+1];
			if(x.r>=y.r){
				y.clear();
				y.l=y.r=x.r;
			}else{
				while(y.l<x.r)
					y.dec(a[y.l++]);
			}
		}
break_outer:;
	}
	std::cout<<'\n';
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

std::vector<int> a;
std::vector<int> pre,nxt;

struct Counter:std::unordered_map<int,int>{
	void inc(int x){
		++(*this)[x];
	}
	void dec(int x){
		auto iter=this->find(x);
		if(0==--iter->second)
			this->erase(iter);
	}
};

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;
	a.resize(n);
	for(int& x:a)std::cin>>x;
	int const old_n=n;
	n=-1;
	a.erase(std::unique(begin(a),end(a)),end(a));

	pre.resize(a.size());
	nxt.resize(a.size(),n);
	{
		std::unordered_map<int,int> last;
		for(unsigned i=0;i<a.size();++i){
			auto iter=last.find(a[i]);
			if(iter==end(last)){
				pre[i]=-1;
				last.insert({a[i],i});
			}else{
				pre[i]=iter->second;
				nxt[pre[i]]=i;
				iter->second=i;
			}
		}
	}

	struct Range{
		int l,r;
	private:
		int size_;
	public:
		Range():size_{}{}
		int size()const{return size_;}
		void clear(){l=r=size_=0;}
		bool have_new_r()const{
			return pre[r]<l;
		}
		void incr(){
			if(have_new_r())
				++size_;
			++r;
		}
		void incl(){
			if(nxt[l]>=r)
				--size_;
			++l;
		}
	};

	std::vector<Range> t(a.size());
	for(unsigned i=0;i<a.size();++i){
		t[i].l=i;
		t[i].r=i;
		t[i].incr();
	}
	for(int i=1;;){
		std::cout<<t.size()<<' ';
		if(i==old_n)
			break;

		++i;
		for(unsigned j=0;;++j){
			auto& x=t[j];
			while(true){
				if(x.r==(int)a.size()){
					t.erase(begin(t)+j+1,end(t)); // invalidates x
					goto break_outer;
				}
				if((int)x.size()==i&&x.have_new_r())
					break;
				x.incr();
			}

			auto& y=t[j+1];
			if(x.r>=y.r){
				y.clear();
				y.l=y.r=x.r;
			}else{
				while(y.l<x.r)
					y.incl();
			}
		}
break_outer:;
	}
	std::cout<<'\n';
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>

std::vector<int> a;
std::vector<int> pre,nxt;

struct Counter:std::unordered_map<int,int>{
	void inc(int x){
		++(*this)[x];
	}
	void dec(int x){
		auto iter=this->find(x);
		if(0==--iter->second)
			this->erase(iter);
	}
};

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;
	a.resize(n);
	for(int& x:a)std::cin>>x;
	int const old_n=n;
	n=-1;
	a.erase(std::unique(begin(a),end(a)),end(a));

	pre.resize(a.size());
	nxt.resize(a.size(),a.size());
	{
		std::unordered_map<int,int> last;
		for(unsigned i=0;i<a.size();++i){
			auto iter=last.find(a[i]);
			if(iter==end(last)){
				pre[i]=-1;
				last.insert({a[i],i});
			}else{
				pre[i]=iter->second;
				nxt[pre[i]]=i;
				iter->second=i;
			}
		}
	}

	struct Range{
		int l,r;
	private:
		int size_;
	public:
		Range():size_{}{}
		int size()const{return size_;}
		void clear(){l=r=size_=0;}
		bool have_new_r()const{
			return pre[r]<l;
		}
		void incr(){
			if(have_new_r())
				++size_;
			++r;
		}
		void incl(){
			if(nxt[l]>=r)
				--size_;
			++l;
		}
	};

	std::vector<Range> t(a.size());
	for(unsigned i=0;i<a.size();++i){
		t[i].l=i;
		t[i].r=i;
		t[i].incr();
	}
	for(int i=1;;){
		std::cout<<t.size()<<' ';
		if(i==old_n)
			break;

		++i;
		for(unsigned j=0;;++j){
			auto& x=t[j];
			while(true){
				if(x.r==(int)a.size()){
					t.erase(begin(t)+j+1,end(t)); // invalidates x
					goto break_outer;
				}
				if((int)x.size()==i&&x.have_new_r())
					break;
				x.incr();
			}

			auto& y=t[j+1];
			if(x.r>=y.r){
				y.clear();
				y.l=y.r=x.r;
			}else{
				while(y.l<x.r)
					y.incl();
			}
		}
break_outer:;
	}
	std::cout<<'\n';
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, int> pii;

# define F first
# define S second
# define endl '\n'
# define sep ' '
# define pb push_back
# define fast_io ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

const ll md = 1e9 + 7;
const int xn = 1e5 + 10;
const int xm = 1e3 + 10;
const int SQ = 400;
const int sq = 1e3 + 10;
const ll inf = 1e18+ 10;

ll power(ll a, ll b) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md : power(a * a % md, b / 2) % md));}
ll zarb(ll a, ll b){return (a * b + 10 * md) % md;}
ll jaam(ll a, ll b){return (a + b + 10 * md) % md;}

int n, a[xn], ans[xn], cnt[xn], last;

void check(int k){
	int t = 0, las = 0;
	memset(cnt, 0, sizeof cnt);
	for (int i = 0; i < n; i ++){
		if (!cnt[a[i]]) t ++;
		cnt[a[i]] ++;
		if (t == k + 1){
			t = 1;
			ans[k] ++;
			for (int j = las; j < i; j ++) cnt[a[j]] --;
			las = i;
		}
	}
	ans[k] ++;
}

int main(){
	fast_io;

	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	for (int i = 1; i <= SQ; i ++) check(i);
	last = n + 1;
	for (int i = 1; i < SQ; i ++){
		int L = SQ, R = last, Mid;
		while (R - L > 1){
			Mid = (L + R) / 2;
			if (!ans[Mid]) check(Mid);
			if (ans[Mid] > i) L = Mid;
			else R = Mid;
		}
		for (int j = last - 1; j >= R; j --) ans[j] = ans[R];
		last = R;
	}
	for (int i = 1; i <= n; i ++) cout << ans[i] << sep;
	cout << endl;

	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, int> pii;

# define F first
# define S second
# define endl '\n'
# define sep ' '
# define pb push_back
# define fast_io ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

const ll md = 1e9 + 7;
const int xn = 1e5 + 10;
const int xm = 1e3 + 10;
const int SQ = 1000;
const int sq = 1e3 + 10;
const ll inf = 1e18+ 10;

ll power(ll a, ll b) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md : power(a * a % md, b / 2) % md));}
ll zarb(ll a, ll b){return (a * b + 10 * md) % md;}
ll jaam(ll a, ll b){return (a + b + 10 * md) % md;}

int n, a[xn], ans[xn], cnt[xn], last;

void check(int k){
	int t = 0, las = 0;
	memset(cnt, 0, sizeof cnt);
	for (int i = 0; i < n; i ++){
		if (!cnt[a[i]]) t ++;
		cnt[a[i]] ++;
		if (t == k + 1){
			t = 1;
			ans[k] ++;
			for (int j = las; j < i; j ++) cnt[a[j]] --;
			las = i;
		}
	}
	ans[k] ++;
}

int main(){
	fast_io;

	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	for (int i = 1; i <= SQ; i ++) check(i);
	last = n + 1;
	for (int i = 1; i < SQ; i ++){
		int L = SQ, R = last, Mid;
		while (R - L > 1){
			Mid = (L + R) / 2;
			if (!ans[Mid]) check(Mid);
			if (ans[Mid] > i) L = Mid;
			else R = Mid;
		}
		for (int j = last - 1; j >= R; j --) ans[j] = ans[R];
		last = R;
	}
	for (int i = 1; i <= n; i ++) cout << ans[i] << sep;
	cout << endl;

	return 0;
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
#pragma GCC optimize(2)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(register int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=200;
int n,flag=0,a[maxn],vis[maxn]={};

inline int calc(int x){
	register int ret=0,cnt=0;
	++flag;
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=cnt+1,vis[a[i]]=flag;
		if(cnt>=x)cnt-=x;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i];
	int x=n,k=1;
	while(x>=limit)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k-1,r=n+1;
		while(l+1<r){
			int mid=l+r>>1;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(l==k-1)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		//if(clock()*100>199*CLOCKS_PER_SEC)break;
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=100;
int n,a[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	int x=n,k=1;
	while(x>=limit&&k<n)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k,r=n+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(calc(l)<i)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
#pragma GCC optimize(2)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(register int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=78;
int n,flag=0,a[maxn],vis[maxn]={};

inline int calc(int x){
	register int ret=0,cnt=0;
	++flag;
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=cnt+1,vis[a[i]]=flag;
		if(cnt>=x)cnt-=x;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i];
	int x=n,k=1;
	while(x>=limit)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k-1,r=n+1;
		while(l+1<r){
			int mid=l+r>>1;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(l==k-1)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		//if(clock()*100>199*CLOCKS_PER_SEC)break;
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
int n,a[maxn],res[maxn],vis[maxn];

int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

void solve(int l,int r,int a,int b){
	if(a+1==b)RREP(i,r,l)res[i]=b;
	else if(l+1==r)res[r]=calc(r);
	else{
		int mid=(l+r)/2,tt=calc(mid);
		solve(l,mid,a,tt),solve(mid,r,tt,b);
	}
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	solve(0,n,0,n);
	REP(i,1,n+1)cout<<res[i]<<" ";cout<<endl;
	assert(calc(1)==n);
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=80;
int n,a[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i];
	int x=n,k=1;
	while(x>=limit)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k-1,r=n+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(l==k-1)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		//if(clock()*100>199*CLOCKS_PER_SEC)break;
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
#pragma GCC optimize(2)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(register int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=60;
int n,flag=0,a[maxn],vis[maxn]={};

inline int calc(int x){
	register int ret=0,cnt=0;
	++flag;
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=cnt+1,vis[a[i]]=flag;
		if(cnt>=x)cnt-=x;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i];
	int x=n,k=1;
	while(x>=limit)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k-1,r=n+1;
		while(l+1<r){
			int mid=l+r>>1;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(l==k-1)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		//if(clock()*100>199*CLOCKS_PER_SEC)break;
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=87;
int n,a[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	int x=n,k=1;
	while(x>=limit&&k<n)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k-1,r=n+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(l==k-1)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=70;
int n,a[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	int x=n,k=1;
	while(x>=limit&&k<n)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k,r=n+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(calc(l)<i)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		if(clock()*100>199*CLOCKS_PER_SEC)break;
	}
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
int n,a[maxn],res[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

void solve(int l,int r,int a,int b){
	if(a==b)REP(i,l,r+1)res[i]=a;
	else if(l==r)res[r]=r<n?b:calc(r);
	else{
		int mid=(l+r)/2,tt=calc(mid);
		solve(l,mid,a,tt),solve(mid+1,r,tt+1,b);
	}
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	solve(1,n,n,1);
	REP(i,1,n+1)cout<<res[i]<<" ";cout<<endl;
}


#include<bits/stdc++.h>
#include<stdint.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int (i)=(j);(i)<(k);++(i))
#define RREP(i,j,k) for(int (i)=(j)-1;(i)>=(k);--(i))
#define ALL(a) (a).begin(),(a).end()
#define MST(a,v) memset((a),(v),sizeof(a))
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cout<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de((a)[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif

const int maxn=1e5+9;
const int limit=150;
int n,a[maxn],vis[maxn];

inline int calc(int x){
	int ret=0,cnt=0,flag=1;
	MST(vis,0);
	REP(i,0,n)if(vis[a[i]]!=flag){
		if(!cnt)++ret,++flag;
		cnt=(cnt+1)%x,vis[a[i]]=flag;
	}
	return ret;
}

main(){
	IOS;
	cin>>n;
	REP(i,0,n)cin>>a[i],--a[i];
	int x=n,k=1;
	while(x>=limit&&k<n)cout<<(x=calc(k++))<<" ";
	RREP(i,limit,1){
		int l=k,r=n+1;
		while(l+1<r){
			int mid=(l+r)/2;
			if(calc(mid)<i)r=mid;
			else l=mid;
		}
		if(calc(l)<i)continue;
		while(k<=l){
			cout<<i<<" ";
			++k;
		}
		if(clock()*10>19*CLOCKS_PER_SEC)break;
	}
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
const auto start_time = chrono::steady_clock::now();
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  string s[n];
  unordered_map<string, ull> mp;
  for (register int i = 0; i < n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }

  ull cnt = 0;
  for (const auto x : mp) {
    if (x.second == 2) cnt++;
    if (x.second > 2) cnt += (x.second - 1);
  }
  cout << cnt << "\n";

  for (register int i = 0; i < n; i++) {
    string pin = s[i];
    if (mp[pin] > 1) {
      string npin;
      for (char k = '0'; k < '9'; k++) {
        npin = pin;
        npin[1] = k;
        if (mp[npin] == 0) {
          mp[npin]++;
          break;
        }
      }
      cout << npin << "\n";
      mp[pin]--;
    } else {
      cout << pin << "\n";
    }
  }
  // cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

  const auto _now = chrono::steady_clock::now();
  cerr << "\nTime elapsed: "
       << chrono::duration_cast<chrono::milliseconds>(_now - start_time).count()
       << " ms\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  string s[n];
  unordered_map<string, ull> mp;
  for (register int i = 0; i < n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }

  ull cnt = 0;
  for (const auto x : mp) cnt += (x.second - 1);
  cout << cnt << "\n";

  for (register int i = 0; i < n; i++) {
    string pin = s[i];

    if (mp[pin] > 1) {
      for (char k = '0'; k <= '9'; k++) {
        pin[1] = k;
        if (mp[pin] == 0) {
          mp[pin]++;
          break;
        }
      }
      cout << pin << "\n";
      mp[pin]--;
    } else
      cout << pin << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  register int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  string s[n];
  unordered_map<string, ull> mp;
  for (register int i = 0; i < n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }

  ull cnt = 0;
  for (const auto x : mp) cnt += (x.second - 1);
  cout << cnt << "\n";

  for (register int i = 0; i < n; i++) {
    string pin = s[i], new_pin;

    if (mp[pin] > 1) {
      for (char k = '0'; k <= '9'; k++) {
        new_pin = pin;
        new_pin[1] = k;
        if (mp[new_pin] == 0) {
          mp[new_pin]++;
          break;
        }
      }
      cout << new_pin << "\n";
      mp[pin]--;
    } else
      cout << pin << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  register int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
const auto start_time = chrono::steady_clock::now();
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  string s[n];
  unordered_map<string, ull> mp;
  for (register int i = 0; i < n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }

  ull cnt = 0;
  for (const auto x : mp) {
    if (x.second == 2) cnt++;
    if (x.second > 2) cnt += (x.second - 1);
  }
  cout << cnt << "\n";

  for (register int i = 0; i < n; i++) {
    string pin = s[i];
    if (mp[pin] > 1) {
      string npin;
      bool f = false;
      for (char k = '0'; k < '9'; k++) {
        npin = pin;
        npin[1] = k;
        if (mp[npin] == 0) {
          mp[npin]++;
          f = true;
          break;
        }
      }
      if (!f) {
        for (char k = '0'; k < '9'; k++) {
          npin = pin;
          npin[2] = k;
          if (mp[npin] == 0) {
            mp[npin]++;
            f = true;
            break;
          }
        }
      }
      if (!f) {
        for (char k = '0'; k < '9'; k++) {
          npin = pin;
          npin[3] = k;
          if (mp[npin] == 0) {
            mp[npin]++;
            f = true;
            break;
          }
        }
      }
      if (!f) {
        for (char k = '0'; k < '9'; k++) {
          npin = pin;
          npin[0] = k;
          if (mp[npin] == 0) {
            mp[npin]++;
            f = true;
            break;
          }
        }
      }
      cout << npin << "\n";
      mp[pin]--;
    } else {
      cout << pin << "\n";
    }
  }
  // cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

  const auto _now = chrono::steady_clock::now();
  cerr << "\nTime elapsed: "
       << chrono::duration_cast<chrono::milliseconds>(_now - start_time).count()
       << " ms\n";
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << it->first << endl;
			ok.push_back(it->first);
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if (num[i] == 1)
					continue;
				f(j, 0, 9)
				{
					ok[i][3] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						mp[ok[i]] = 1;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10]= { '0','1','2','3','4','5','6','7','8','9' };
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}
		int big = -1;

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		for (it = mp.begin();it != mp.end();it++)
			cout << it->first << endl;

		str[0] = '1';
		str[1] ='1';
		str[2] = '1';
		if(k)
		f(j, 0, 9)
		{
			str[3] =now[j];
			if (!mp.count(str))//meiyou
			{
				cout << str << endl;
				k--;
			}
			if (k == 0)
				break;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::reverse_iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		for (it = mp.rbegin();it != mp.rend();it++)
		{
			cout << it->first << endl;
			ok.push_back(it->first);
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if (num[i] == 1)
					continue;
				f(j, 0, 9)
				{
					ok[i][0] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						mp[ok[i]] = 1;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::reverse_iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;

			else//不在，加入
			{
				ok.push_back(str);
				mp[str] = 1;
			}
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		int i = 0;
		for (it = mp.rbegin();it != mp.rend();it++)
		{
			cout << ok[i] << endl;i++;
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if (num[i] == 1)
					continue;
				f(j, 0, 9)
				{
					ok[i][0] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						mp[ok[i]] = 1;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << it->first << endl;
			ok.push_back(it->first);
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if (num[i] == 1)
					continue;
				f(j, 0, 9)
				{
					ok[i][0] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						mp[ok[i]] = 1;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;

			else//不在，加入
			{
				ok.push_back(str);
				mp[str] = 1;
			}
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		int i = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << ok[i] << endl;i++;
			num[cot++] = it->second;//ok序列
		}

		if (k)
		{
			for (it = mp.begin();it != mp.end();it++)
			{
				if (it->second == 1)
					continue;//1
				//>1
				else {
					string mid = it->first;
					f(j, 0, 9)
					{
						mid[0] = now[j];
						if (!mp.count(mid))
						{
							cout << mid << endl;
							mp[mid] = 1;
							it->second--;
						}
						if (it->second == 1)
							break;
					}
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << it->first << endl;
			ok.push_back(it->first);
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if(num[i]>1)
				f(j, 0, 9)
				{
					ok[i][3] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;

			else//不在，加入
			{
				ok.push_back(str);
				mp[str] = 1;
			}
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		int i = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << ok[i] << endl;i++;
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				if (num[i] == 1)
					continue;
				f(j, 0, 9)
				{
					ok[i][0] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						mp[ok[i]] = 1;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp;
map<string, int>::iterator it;
char str[5];
char now[10]= { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int num[10];
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;
			else//不在，加入
				mp[str] = 1;
		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		int cot = 0;
		for (it = mp.begin();it != mp.end();it++)
		{
			cout << it->first << endl;
			ok.push_back(it->first);
			num[cot++] = it->second;
		}

		if (k)
		{
			for (int i = 0;i < cot;i++)
			{//遍历每个string
				f(j, 0, 9)
				{
					ok[i][3] = now[j];
					if (!mp.count(ok[i]))
					{
						cout << ok[i] << endl;
						num[i]--;
					}
					if (num[i] == 1)
						break;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<sstream>
#include<set>
#define f(i,a,b) for(register int i=a;i<=b;i++)
#define fd(i,a,b) for(register int i=a;i>=b;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
inline int in()
{
	char ch = getchar();
	int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }
	return x * f;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
const int N = 1e9 + 5;
int t, n;
map<string, int> mp,book;
map<string, int>::iterator it;
char str[5];
char now[10] = { '0','1','2','3','4','5','6','7','8','9' };
vector<string> ok;
int main()
{
	cin >> t;
	while (t--)
	{
		mp.clear();ok.clear();
		cin >> n;
		f(i, 1, n)
		{
			scanf("%s", str);
			if (mp.count(str))//在
				mp[str]++;

			else//不在，加入
			{
				mp[str] = 1;
				book[str] = 1;

			}ok.push_back(str);

		}

		/*for (it = mp.begin();it != mp.end();it++)
		{//找出最大出现字符
			big = max(big, it->second);
		}
		cout << big << endl;*/
		//两部分，1mp，2自己找
		int k = n - mp.size();//除去mp多少
		cout << k << endl;
		//哎，读题，每一行要和之前对应，不只是改变集合就可以了

	for(int i=0;i<ok.size();i++)
	{
		it = mp.find(ok[i]);//必须熟练各种容器,ok维持输入顺序，mp记录字符串出现次数
		if (it->second == 1 || book[it->first] == 1)//==不仅无重复维持原来输出，重复的第一次出现也要维持
		{
			cout << it->first << endl;
			book[it->first]++;
		}
			//>1
			else {
				string mid = it->first;
				f(j, 0, 9)
				{
					mid[0] = now[j];
					if (!mp.count(mid))
					{
						cout << mid << endl;
						mp[mid] = 1;
						it->second--;
						break;//变一次就可
					}
				}
			}
		}

	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    // debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        unordered_map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            if(i.second.size() == 1)
                continue ;
            vector<int> temp = i.second;
            // debug(i.second.size());
            int c1 = 0;
            for(auto j : temp){
                // debug(j);
                c1 += 1;
                if(c1 == temp.size())
                    break;
                if(mp[a[j]].size() == 1)
                    continue;
                // debug(j);
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    // debug(a[j]);
                    for(int p = 0 ; p < 9 ; p ++){
                        char c = a[j][k];
                        a[j][k] = p + '0';
                        // debug(a[j][0]);
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                        a[j][k] = c;
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    // debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        unordered_map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            if(i.second.size() == 1)
                continue ;
            vector<int> temp = i.second;
            // debug(i.second.size());
            int c1 = 0;
            for(auto j : temp){
                // debug(j);
                c1 += 1;
                if(c1 == temp.size())
                    break;
                if(mp[a[j]].size() == 1)
                    continue;
                // debug(j);
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    // debug(a[j]);
                    for(int p = 0 ; p < 9 ; p ++){
                        char c = a[j][k]
                        a[j][k] = p + '0';
                        // debug(a[j][0]);
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                        a[j][k] = c;
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    // debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        unordered_map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            if(i.second.size() == 1)
                continue ;
            vector<int> temp = i.second;
            // debug(i.second.size());
            int c1 = 0;
            for(auto j : temp){
                // debug(j);
                c1 += 1;
                if(c1 == temp.size())
                    break;
                if(mp[a[j]].size() == 1)
                    continue;
                // debug(j);
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    // debug(a[j]);
                    for(int p = 0 ; p < 9 ; p ++){
                        a[j][0] = p + '0';
                        // debug(a[j][0]);
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        unordered_map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            if(i.second.size() == 1)
                continue ;
            vector<int> temp = i.second;
            // debug(i.second.size());
            int c1 = 0;
            for(auto j : temp){
                // debug(j);
                c1 += 1;
                if(c1 == temp.size())
                    break;
                if(mp[a[j]].size() == 1)
                    continue;
                // debug(j);
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    // debug(a[j]);
                    for(int p = 0 ; p < 9 ; p ++){
                        a[j][0] = p + '0';
                        // debug(a[j][0]);
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    // debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        unordered_map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            if(i.second.size() == 1)
                continue ;
            vector<int> temp = i.second;
            int c1 = 0;
            for(auto j : temp){
                c1 += 1;
                if(c1 == temp.size())
                    break;
                if(mp[a[j]].size() == 1)
                    continue;
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    for(int p = 0 ; p <= 9 ; p ++){
                        char c = a[j][k];
                        a[j][k] = p + '0';
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                        a[j][k] = c;
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    // debug(t);
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            // debug(a[i]);
            mp[a[i]].eb(i);
        }
        // cout << mp["6864"].size() << endl;
        int ans = 0;
        for(auto i : mp){
            // if(i.second.size() == 1)
            //     continue ;
            vector<int> temp = i.second;
            int c1 = 0;
            // debug2(i.first, i.second.size());
            for(auto j : temp){
                c1 += 1;
                if(c1 == temp.size())
                    break;
                // if(mp[a[j]].size() == 1)
                //     continue;
                // debug(a[j]);
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    for(int p = 0 ; p <= 9 ; p ++){
                        char c = a[j][k];
                        a[j][k] = p + '0';
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                        a[j][k] = c;
                    }
                    if(flag)
                        break;
                }
            }
        }
        // cout << mp["6864"].size() << endl;
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define rep(i,n) for(ll i=0;i<(n);i++)
#define fr(i,a,b) for(ll i=(a);i<(b);i++)
#define frd(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl "\n"
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define inf ((long long) 1e18 + 10)
#define ve vector<ll>
#define mod 1000000007
using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    fileIO
    #endif
    ll t;
    // t = 1;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<string> a(n);
        map<string, vector<int>> mp;
        for(int i = 0 ; i < n ; i ++){
            cin >> a[i];
            mp[a[i]].eb(i);
        }
        int ans = 0;
        for(auto i : mp){
            vector<int> temp = i.second;
            int c1 = 0;
            for(auto j : temp){
                c1 += 1;
                if(c1 == temp.size())
                    break;
                ans += 1;
                int flag = 0;
                for(int k = 0 ; k < 4 ; k ++){
                    for(int p = 0 ; p <= 9 ; p ++){
                        char c = a[j][k];
                        a[j][k] = p + '0';
                        if(mp.find(a[j]) == mp.end()){
                            flag = 1;
                            mp[a[j]].eb(k);
                            break;
                        }
                        a[j][k] = c;
                    }
                    if(flag)
                        break;
                }
            }
        }
        cout << ans << endl;
        for(auto i : a)
            cout << i << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
	unordered_map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
		while (n--) {
			cin >> s;
			mp[s]++;
			if (mp[s] > 1) {
				cnt++;
				mp[s]--;
				int i = 0;
				while (mp.find(s) != mp.end()) {
					s[0] = arr[i];
					i++;
				}
				mp[s]=1;
			}
				v.push_back(s);
		}
			cout << cnt << endl;
			for (int i=0;i<v.size();i++)
				cout << v[i] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
	unordered_map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
		while (n--) {
			cin >> s;
			mp[s]++;
			while (mp[s] > 1) {
				cnt++;
				int i = 0;
				while (mp.find(s) != mp.end()) {
					s[0] = arr[i];
					i++;
				}
				mp[s]--;
			}
				v.push_back(s);
		}
			cout << cnt << endl;
			for (int i=0;i<v.size();i++)
				cout << v[i] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
		vector<string>brr;
	map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
			while (n--) {
				cin >> s;
				brr.push_back(s);
				mp[s]++;
			}
			for (int i = 0; i < brr.size();i++) {
				if (mp[brr[i]] > 1) {
					mp[brr[i]]--;
					s = brr[i];
					cnt++;
					int ii = 0;
					while (mp.find(s) != mp.end()) {
						s[0] = arr[ii];
						ii++;
					}
					mp[s] = 1;
					brr[i]=s;
				}
			}
			cout << cnt << endl;
			for (int i = 0; i < brr.size();i++) {
				cout << brr[i] << endl;
			}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	unordered_map<string, int>mp;
	int t;
	cin >> t;
	while (t--) {
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
		while (n--) {
			cin >> s;
			mp[s]++;
			while (mp[s] > 1) {
				cnt++;
				int i = 0,j=0;
				char ch = s[0];
				while (mp.find(s) != mp.end()) {
					s[j] = arr[i];
					i++;
					if (i == 10) {
						i = 0;
						s[0] = ch;
						j++;
					}
				}
				mp[s]--;
			}
				v.push_back(s);
		}
			cout << cnt << endl;
			for (int i=0;i<v.size();i++)
				cout << v[i] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	unordered_map<string, int>mp;
	int t;
	cin >> t;
	while (t--) {
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
		while (n--) {
			cin >> s;
			mp[s]++;
			while (mp[s] > 1) {
				cnt++;
				int i = 0;
				while (mp.find(s) != mp.end()) {
					s[0] = arr[i];
					i++;
				}
				mp[s]--;
			}
				v.push_back(s);
		}
			cout << cnt << endl;
			for (int i=0;i<v.size();i++)
				cout << v[i] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
	unordered_map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
			while (n--) {
				cin >> s;
				mp[s]++;
			}
			int ii = mp.size();
			for (auto a : mp) {
				if (!ii)
					stop;
				v.push_back(a.first);
				while (a.second > 1) {
					s = a.first;
					cnt++;
					a.second--;
					int i = 0;
					while (mp.find(s) != mp.end()) {
						s[0] = arr[i];
						i++;
					}
					mp[s] = 1;
					v.push_back(s);
				}
				ii--;
			}
			cout << cnt << endl;
			for (int i = 0; i < v.size();i++) {
				cout << v[i] << endl;
			}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
	unordered_map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
			while (n--) {
				cin >> s;
				mp[s]++;
			}
			int ii = mp.size();
			for (auto a : mp) {
				if (!ii)
					stop;
				v.push_back(a.first);
				while (a.second > 1) {
					s = a.first;
					cnt++;
					a.second--;
					int i = 0;
					while (mp.find(s) != mp.end()) {
						s[0] = arr[i];
						i++;
					}
					mp[s] = 1;
					v.push_back(s);
				}
				ii--;
			}
			cout << cnt << endl;
			for (auto a : v) {
				cout << a << endl;
			}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int arr[10][10];
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
	unordered_map<string, int>mp;
		int n, cnt = 0;
		cin >> n;
		string s;
			vector<string>v;
			vector <char>arr{ '0','1','2','3','4','5','6','7','8','9' };
		while (n--) {
			cin >> s;
			mp[s]++;
			while (mp[s] > 1) {
				cnt++;
				int i = 0;
				mp[s]--;
				while (mp.find(s) != mp.end()) {
					s[0] = arr[i];
					i++;
				}
			}
				v.push_back(s);
		}
			cout << cnt << endl;
			for (int i=0;i<v.size();i++)
				cout << v[i] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define skip continue
#define sz(n) n.size()
#define stop break
#define pi  acos(-1)
#define endl "\n"
#define ll long long
#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define ull unsigned long long
int main() {
	Open();
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		ll k = n;
		vector<string>v(n);
		map<string, ll>mp;
		for (int i = 0; i < n; i++)
		{
			string s;
			cin >> v[i];
			mp[v[i]]++;
		}

		cout << k - sz(mp) << endl;;
		for (int i = 0; i < n; i++)
		{
			if (mp[v[i]] > 1) {
				//cout << v[i] << " " << mp[v[i]] << endl << endl;;
				mp[v[i]]--;
				for (int j = 0; j < sz(v[i]); j++)
				{
					string s = v[i];
					for (char k = '0'; k <= '9'; k++) {
						char c = k, b;
						b = s[j];
						s[j] = c;
						if (mp[s] >= 1) {
							s[j] = b;
						}
						else {
							v[i] = s;
							mp[v[i]]++;
							j = 5; break;
						}
					}
				}
			}
		}
		for (int i = 0; i < n; i++)cout << v[i] << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string,int>mp;
int main() {
	int t;
	cin >> t;
	while(t--) {
		mp.clear();
		int n;
		cin >> n ;
		string a[15];
		ll cnt = 0;
		for(int i=0;i<n;i++) {
			cin >> a[i];
			if(mp[a[i]])
			cnt++;
			else
			mp[a[i]] = 1;
		}
		cout <<cnt<<endl;
		mp.clear();
		for(int i=0;i<n;i++) {
			mp[a[i]]++;
			a[i][3] = (a[i][3]-'0'+mp[a[i]]-1)%10+'0';
			cout << a[i] <<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
vector<int>v;
int book[10001];
int a[15];
int main() {
	int t;
	cin >> t;
	while(t--) {
		memset(book,0,sizeof(book));
		mp.clear();
		v.clear();
		int n;
		cin >> n;
		ll cnt = 0,w = 0;
		for(int i=0;i<n;i++) {
			cin >> a[i];
			if(book[a[i]]) {
				cnt++;
			}
			else
			book[a[i]] = 1;
		}
		for(int i=0;i<n;i++) {
		     w = 1;
			if(mp[a[i]]) {
				while(mp[a[i]+w]&&a[i]+w<100000) {
					w++;
				}
				if(!mp[a[i]+w]) {
					v.push_back(a[i]+w);
					mp[a[i]+w] = 1;
					continue;
				}
				else{
					w = -1;
					while(mp[a[i]+w]&&a[i]+w>=1000)
					w--;
					if(!mp[a[i]+w]) {
						v.push_back(a[i]+w);
						mp[a[i]+w] = 1;
					}
				}
			}
			else {
				v.push_back(a[i]);
				mp[a[i]] = 1;
			}
		}
		cout << cnt <<endl;
		for(int i=0;i<v.size();i++) {
			if(v[i]<10) {
				cout<<"000"<<v[i]<<endl;
			}
			else if(v[i]<100){
				cout<<"00"<<v[i]<<endl;
			}
			else if(v[i]<1000) {
				cout<<"0"<<v[i]<<endl;
			}
			else
			cout<<v[i]<<endl;
		}
	}
}


#pragma GCC optimize("inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
map<string,int>mp;
map<string,int>mp1;
map<string,int>mp2;
map<string,int>mp3;
string a[15];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	//priority_queue<int>q;
	while(t--) {
	    mp1.clear();
		mp.clear();
		mp2.clear();
		mp3.clear();
		int n;
		cin >> n;
		string str = "";
		for(int i=0;i<n;i++) {
			cin >> a[i];
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
		    mp[str]++;
		    mp3[str]++;
		}
		ll cnt = 0;
		for(int i=0;i<n;i++) {
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
			if(mp[str]>1&&!mp2[str]){
				cnt+=mp[str]-1;
				mp2[str] = 1;
			}
		}
		cout<<cnt<<endl;
		for(int i=0;i<n;i++) {
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
			if(mp[str]>1&&mp1[str]) {
				//cout<<mp[a[i]];
				a[i][3]=((a[i][3]+mp3[str]-mp[str]+1-'0')%10+'0');
				mp[str]--;
			}
			if(n==10&&mp[str]==1) {
				a[i][1]=((a[i][1]+1-'0')%10+'0');
				cout<<a[i]<<endl;
			}
			else
			cout<<a[i]<<endl;
			mp1[str] = 1;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
vector<int>v;
int a[15];
int main() {
	int t;
	cin >> t;
	while(t--) {
		mp.clear();
		v.clear();
		int n;
		cin >> n;
		ll cnt = 0,w = 0;
		for(int i=0;i<n;i++) {
			cin >> a[i];
		     w = 1;
			if(mp[a[i]]) {
				while(mp[a[i]+w]&&a[i]+w<100000) {
					w++;
				}
				if(!mp[a[i]+w]) {
					v.push_back(a[i]+w);
					mp[a[i]+w] = 1;
					continue;
				}
				else{
					w = -1;
					while(mp[a[i]+w]&&a[i]+w>=1000)
					w--;
					if(!mp[a[i]+w]) {
						v.push_back(a[i]+w);
						mp[a[i]+w] = 1;
					}
				}
			}
			else {
				v.push_back(a[i]);
				mp[a[i]] = 1;
				cnt++;
			}
		}
		cout << cnt <<endl;
		for(int i=0;i<v.size();i++) {
			if(v[i]<10) {
				cout<<"000"<<v[i]<<endl;
			}
			else if(v[i]<100){
				cout<<"00"<<v[i]<<endl;
			}
			else if(v[i]<1000) {
				cout<<"0"<<v[i]<<endl;
			}
			else
			cout<<v[i]<<endl;
		}
	}
}


#pragma GCC optimize("inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
map<string,int>mp;
map<string,int>mp1;
map<string,int>mp2;
map<string,int>mp3;
string a[15];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	//priority_queue<int>q;
	while(t--) {
	    mp1.clear();
		mp.clear();
		mp2.clear();
		mp3.clear();
		int n;
		cin >> n;
		string str = "";
		for(int i=0;i<n;i++) {
			cin >> a[i];
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
		    mp[str]++;
		    mp3[str]++;
		}
		ll cnt = 0;
		for(int i=0;i<n;i++) {
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
			if(mp[str]>1&&!mp2[str]){
				cnt+=mp[str]-1;
				mp2[str] = 1;
			}
		}
		cout<<cnt<<endl;
		for(int i=0;i<n;i++) {
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
			if(mp[str]>1&&mp1[str]) {
				//cout<<mp[a[i]];
				a[i][3]=((a[i][3]+mp3[str]-mp[str]+1-'0')%10+'0');
				mp[str]--;
			}
			cout<<a[i]<<endl;
			mp1[str] = 1;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
vector<int>v;
int a[15];
int main() {
	int t;
	cin >> t;
	while(t--) {
		mp.clear();
		v.clear();
		int n;
		cin >> n;
		ll cnt = 0,w = 0;
		for(int i=0;i<n;i++) {
			cin >> a[i];
		     w = 1;
			if(mp[a[i]]) {
				cnt++;
				while(mp[a[i]+w]&&a[i]+w<100000) {
					w++;
				}
				if(!mp[a[i]+w]) {
					v.push_back(a[i]+w);
					mp[a[i]+w] = 1;
					continue;
				}
				else{
					w = -1;
					while(mp[a[i]+w]&&a[i]+w>=1000)
					w--;
					if(!mp[a[i]+w]) {
						v.push_back(a[i]+w);
						mp[a[i]+w] = 1;
					}
				}
			}
			else {
				v.push_back(a[i]);
				mp[a[i]] = 1;
			}
		}
		cout << cnt <<endl;
		for(int i=0;i<v.size();i++) {
			if(v[i]<10) {
				cout<<"000"<<v[i]<<endl;
			}
			else if(v[i]<100){
				cout<<"00"<<v[i]<<endl;
			}
			else if(v[i]<1000) {
				cout<<"0"<<v[i]<<endl;
			}
			else
			cout<<v[i]<<endl;
		}
	}
}


#pragma GCC optimize("inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rint register int
map<string,int>mp;
map<string,int>mp1;
map<string,int>mp2;
map<string,int>mp3;
map<string,int>mp4;
string a[15];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	//priority_queue<int>q;
	while(t--) {
		mp4.clear();
	    mp1.clear();
		mp.clear();
		mp2.clear();
		mp3.clear();
		int n;
		cin >> n;
		string str = "";
		for(int i=0;i<n;i++) {
			cin >> a[i];
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
		    mp[str]++;
		    mp3[str]++;
		    mp4[a[i]]++;
		}
		ll cnt = 0;
		for(int i=0;i<n;i++) {
			if(mp4[a[i]]>1&&!mp2[a[i]]){
				cnt+=mp4[a[i]]-1;
				mp2[a[i]] = 1;
			}
		}
		cout<<cnt<<endl;
		for(int i=0;i<n;i++) {
			str="";
			str+=a[i][0];
			str+=a[i][1];
			str+=a[i][2];
			if(mp[str]>1&&mp1[str]&&mp4[a[i]]>1) {
				//cout<<mp[a[i]];
				a[i][3]=((a[i][3]+mp3[str]-mp[str]+1-'0')%10+'0');
				mp[str]--;
			}
			cout<<a[i]<<endl;
			mp1[str] = 1;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string,int>mp;
map<string,int>mp1;
int main() {
	int t;
	cin >> t;
	while(t--) {
		mp.clear();
		mp1.clear();
		int n;
		cin >> n ;
		string a[15];
		ll cnt = 0;
		for(int i=0;i<n;i++) {
			cin >> a[i];
			if(mp[a[i]])
			cnt++;
			else
			mp[a[i]] = 1;
		}
		cout <<cnt<<endl;
		int w = 0;
		string b;
		for(int i=0;i<n;i++) {
			w = 0;
			b = a[i];
			if(!mp1[a[i]]) {
				cout << a[i] <<endl;
					mp1[a[i]] = 1;
				continue;
			}
		    while(mp[b]) {
		    	b = a[i];
		      b[3] = (b[3]-'0'+w)%10+'0';
		      w++;
			}
			mp[b]=1;
			cout << b <<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		bool change = false, g = false;
		int i = 0;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			g = false;
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(find(ar.begin(), ar.end(), s) != ar.end()){
				if(s[i] == '0') s[i] = '9';
				else s[i] = ((s[i] - '0') - 1) + '0';
				i++, c = s[i];
				g = true;
				continue;
			}
			if(s[i] == c && i < 4) i++, c = s[i];
			change = true;
		}
		if(g){
			it--;
			continue;
		}
		st.push_back(s);
		if(change) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		bool change = false;
		int i = 0;
		char c = s[i];
		while(find(st.begin(), st.end(), s) != st.end()){
			bool g = false;
			if(s[i] == '9') s[i] = '0';
			else s[i] = ((s[i] - '0') + 1) + '0';
			if(find(ar.begin(), ar.end(), s) != ar.end()){
				if(s[i] == '0') s[i] = '9';
				else s[i] = ((s[i] - '0') - 1) + '0';
				i++, c = s[i];
				g = true;
				continue;
			}
			if(s[i] == c && i < 4) i++, c = s[i];
			change = true;
		}
		if(g){
			it--;
			continue;
		}
		st.push_back(s);
		if(change) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	vector <string> st, ar;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		ar.push_back(s);
	}
	for(int it = 0 ; it < n; it++){
		string s;
		s = ar[it];
		if(find(st.begin(), st.end(), s) != st.end()){
			for(int i = 0; i < 4; i++){
				bool ok = false;
				string temp = s;
				for(char x = '0'; x <= '9'; x++){
					temp[i] = x;
					if(find(ar.begin(), ar.end(), temp) == ar.end()){
						ar.push_back(temp);
						ok = true;
						s = temp;
						break;
					}
				}
				if(ok) break;
			}
		}
		st.push_back(s);
	}
	for(int i = 0; i < n; i++){
		if(ar[i] != st[i]) ans++;
	}
	cout << ans << endl;
	for(string i : st) cout << i << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}