#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) { a = max(a, b); } template void chmin(T& a, const T& b) { a = min(a, b); } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while(tt--) { int n; cin >> n; VI p(n); rep(i, n) cin >> p[i], p[i] -= i + 1; bool ok = true; rep(i, n) { if (p[i] < 0) { for(int j = i + p[i] + 1; j < i; j++) { if (p[j] == 0) ok = false; } } else if (p[i] > 0) { for(int j = i + 1; j < i + p[i]; j++) { if (p[j] == 0) ok = false; } } } if (!ok) { cout << -1 << '\n'; continue; } VI ans; rep(i, n) { if (p[i] == 0) continue; int t = -1; for(int j = i; j < n; j++) { if (j + p[j] == i) { t = j; break; } } while(t > i) { int k = t - 1; while(k >= i) { if (p[k] != -1) break; k--; } if (k == i - 1) { for(; t > i; t--) { ans.emplace_back(t - 1); swap(p[t - 1], p[t]); p[t - 1]--; p[t]++; } } else { ans.emplace_back(k); swap(p[k], p[k + 1]); p[k]--; p[k]++; if (k == t - 1) t = k; } } } int sz = ans.size(); cout << sz << '\n'; rep(i, sz) cout << ans[i] + 1 << " \n"[i + 1 == sz]; } }