#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 T, t; RI(T);
  REP(0, T, t) {
    i64 N; RI(N);
    vi p(N); RVI(p);
    vi p0 = p;
    for(auto &pp: p) {
      --pp;
    }

    unordered_set<i64> pos[2];
    REP(0, N-1, i) {
      if(p[i] > p[i+1]) {
        pos[i%2].insert(i);
      }
    }

#if 0
    WVI(p);
    cerr << "pos: ";
    for(auto &pp: pos[0]) { cerr << pp << " "; }
    for(auto &pp: pos[1]) { cerr << pp << " "; }
    cerr << endl;
#endif

    vi ans;
    i64 cur = 0;
    while(!pos[0].empty() || !pos[1].empty()) {
      //cerr << endl;
      i64 pr = -1;
      if(pos[cur%2].empty()) {
        pr = cur % 2;
      }
      else {
        pr = *pos[cur%2].begin();
      }
      ans.pb(pr+1);

      //cerr << "swap " << pr << " " << pr + 1 << endl;
      swap(p[pr], p[pr+1]);
      for(i64 i=pr-1;i<=pr+1;++i) {
        if(0 <= i && i < N - 1) {
          if(p[i] > p[i+1]) {
            pos[i%2].insert(i);
          }
          else {
            auto it = pos[i%2].find(i);
            if(it != pos[i%2].end()) {
              pos[i%2].erase(it);
            }
          }
        }
      }
      ++cur;

#if 0 
      WVI(p);
      cerr << "pos: ";
      for(auto &pp: pos[0]) { cerr << pp << " "; }
      for(auto &pp: pos[1]) { cerr << pp << " "; }
      cerr << endl;
#endif
    }

    REP(0, N, i) {
      if(p[i] != i) {
        WVI(p0);
        WVI(p);
      }
      assert(p[i] == i);
    }
    assert(sz(ans) <= N * N);
    WI(sz(ans));
    WVI(ans);
  }

  return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long arr[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
        }
    }
    int dif[n];
    int min=arr[0][0],minindex=0;
    for(int i=1;i<n;i++){
        if(arr[i][0]<min){
            min=arr[i][0];
            minindex=i;
        }
    }

    for(int i=0;i<n;i++){
        dif[i]=arr[i][0]-arr[minindex][0];
        for(int j=0;j<n;j++){
            if( ( arr[i][j] - arr[minindex][j] ) != dif[i] ){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        cout<<dif[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<n;i++){
        cout<<arr[minindex][i]<<" ";
    }
    cout<<endl;
    
}