#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long M = 1000000007;
void dfs(long long st, vector<vector<long long> > &v, vector<bool> &vis,
         vector<long long> &par) {
  if (vis[st]) return;
  vis[st] = true;
  for (long long i = 0; i < v[st].size(); i++) {
    if (vis[v[st][i]]) continue;
    par[v[st][i]] = st;
    dfs(v[st][i], v, vis, par);
  }
  return;
}
long long pow1(long long a, long long b, long long mod) {
  int res = 1;
  if (b < 0) b += mod - 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return res % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long no = 1;
  cin >> no;
  for (long long w = 0; w < no; w++) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    map<long long, long long> m;
    stack<long long> s;
    for (long long i = 0; i < n; i++) m[a[i]]++;
    long long st = 0;
    long long ans = 0;
    vector<long long> v;
    long long tmp;
    long long done = 0;
    map<long long, long long> don;
    long long tmp2;
    while ((st <= n || !s.empty()) && done < n) {
      if (!s.empty()) {
        tmp = s.top();
        tmp2 = tmp;
        s.pop();
      } else {
        while (m[st] > 0) st++;
        tmp = st;
        tmp2 = st;
      }
      if (tmp == n) {
        while (don[done] > 0) done++;
        tmp = done;
      }
      if (tmp == n) break;
      v.push_back(tmp + 1);
      don[tmp]++;
      ans++;
      m[tmp2]++;
      m[a[tmp]]--;
      if (m[a[tmp]] == 0 && a[tmp] < st) s.push(a[tmp]);
      a[tmp] = tmp2;
    }
    cout << v.size() << endl;
    for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
  }
  return 0;
}
