#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, k;
  cin >> t;
  for (int u = 0; u < t; ++u) {
    cin >> n;
    vector<int> a(n);
    vector<int> b(n + 1, 0);
    priority_queue<int> c;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      ++b[a[i]];
    }
    for (int i = 0; i < n + 1; ++i) {
      if (b[i] == 0) c.push(-i);
    }
    vector<int> ans(0);
    for (int i = 0; i < n; ++i) {
      while (a[i] != i) {
        while (c.top() != -n) {
          k = -c.top();
          --b[a[k]];
          ans.push_back(k + 1);
          c.pop();
          if (b[a[k]] == 0) {
            c.push(-a[k]);
          }
          a[k] = k;
          ++b[k];
        }
        if (a[i] != i) {
          k = i + 1;
          while (a[k] != i) {
            ++k;
          }
          ans.push_back(k + 1);
          --b[a[k]];
          c.pop();
          if (b[a[k]] == 0) {
            c.push(-a[k]);
          }
          a[k] = n;
          ++b[n];
        }
      }
    }
    cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << " ";
    }
    cout << '\n';
  }
  return 0;
}
