#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    set<pair<int, int>> ss;
    unordered_map<int, int> freq;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      freq[arr[i]]++;
    }
    for (int i = 0; i <= n; i++) ss.insert({0, i});
    for (auto &x : freq) {
      auto itr = ss.find({0, x.first});
      pair<int, int> tmp = (*itr);
      tmp.first += x.second;
      ss.erase(itr);
      ss.insert(tmp);
    }
    vector<int> ans;
    while (true) {
      auto itr = ss.begin();
      if (itr->second == n) break;
      pair<int, int> tmp = (*itr);
      tmp.first++;
      freq[tmp.second]++;
      ss.erase(itr);
      ss.insert(tmp);
      int the_num_at = arr[tmp.second];
      auto itr2 = ss.find({freq[the_num_at], the_num_at});
      pair<int, int> tmp2 = (*itr2);
      tmp2.first--;
      freq[tmp2.second]--;
      ss.erase(itr2);
      ss.insert(tmp2);
      arr[tmp.second] = tmp.second;
      ans.push_back(tmp.second);
    }
    vector<int> vis(n);
    for (int i = 0; i < n; i++) {
      if (vis[i] == 1) continue;
      if (i == arr[i]) {
        vis[i] = 1;
        continue;
      } else {
        int j = i;
        int min_ind = j;
        int min_val = arr[j];
        vector<int> indices;
        while (vis[j] == 0) {
          vis[j] = 1;
          indices.push_back(j);
          min_val = min(min_val, arr[j]);
          j = arr[j];
        }
        for (int z = 0; z < indices.size(); z++) {
          int sz = indices.size();
          if (arr[indices[z]] == min_val) {
            ans.push_back(indices[z]);
            for (int k = 0; k < sz; k++)
              ans.push_back(indices[(k + z + 1) % sz]);
            break;
          }
        }
      }
    }
    cout << ans.size() << "\n";
    for (auto x : ans) cout << x + 1 << " ";
    cout << "\n";
  }
  return 0;
}
