// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<int> c(n);
    cin >> c;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    constexpr int cmax = 100000;
    array<int, cmax + 1> color;
    rep(i, cmax + 1) color[i] = 0;
    vector<int> good;
    good.reserve(n);
    auto dfs = [&](auto &&dfs, int v, int p) -> void {
        if (!color[c[v]]++) good.push_back(v);
        for (int u : g[v]) {
            if (u != p) dfs(dfs, u, v);
        }
        --color[c[v]];
    };
    dfs(dfs, 0, -1);
    sort(all(good));
    for (int v : good) cout << v + 1 << "\n";
}
#include<bits/stdc++.h>
using namespace std ;

#define MAXN 507

int n ;
int a[ MAXN ] ;
vector < int > v ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
    v.clear ( ) ;
}

void solve ( ) {
    if ( n == 2 ) {
        if ( a[ 1 ] == 2 ) {
            printf ( "1\n1\n" ) ;
            return ;
        }
        else {
            printf ( "0\n" ) ;
            return ;
        }
    }
    int def_odd = n - 2 ;
    int def_even = n - 1 ;
    if ( ( def_odd % 2 ) == 0 ) { swap ( def_even , def_odd ) ; }

    int len = 0 ;
    while ( 1 ) {
        bool fl = false ;
        for ( int i = 1 ; i < n ; ++ i ) {
            if ( a[ i ] > a[ i + 1 ] ) {
                fl = true ;
                break ;
            }
        }
        if ( fl == false ) { break ; }
        ++ len ;
        int st = 1 ;
        if ( ( len % 2 ) == 0 ) { st = 2 ; }
        fl = false ;
        for ( int i = st ; i < min ( def_odd , def_even ) ; i += 2 ) {
            if ( a[ i ] > a[ i + 1 ] ) {
                fl = true ;
                swap ( a[ i ] , a[ i + 1 ] ) ;
                v.push_back ( i ) ;
                break ;
            }
        }
        if ( fl == false ) {
            if ( ( len % 2 ) == 0 ) {
                swap ( a[ def_even ] , a[ def_even + 1 ] ) ;
                v.push_back ( def_even ) ;
            }
            else {
                swap ( a[ def_odd ] , a[ def_odd + 1 ] ) ;
                v.push_back ( def_odd ) ;
            }
        }
    }
    while ( a[ n - 2 ] > a[ n - 1 ] || a[ n - 1 ] > a[ n ] ) {
        ++ len ;
        if ( ( len % 2 ) == 0 ) {
            swap ( a[ def_even ] , a[ def_even + 1 ] ) ;
            v.push_back ( def_even ) ;
        }
        else {
            swap ( a[ def_odd ] , a[ def_odd + 1 ] ) ;
            v.push_back ( def_odd ) ;
        }
    }
    printf ( "%d\n" , len ) ;
    for ( int i = 0 ; i < len ; ++ i ) {
        printf ( "%d " , v[ i ] ) ;
    }
    printf ( "\n" ) ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    // t = 1 ;
    // cin >> t ;
    scanf ( "%d" , &t ) ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}
