#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0;i<(int)(n);++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<int> vec(n);
  vector<ll> re_sum(n);
  rep(i,n) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  ll sum = 0, ans = 0;
  for (ll i = 0; i < n; ++i) {
    ans += vec[i]*i - sum;
    sum += vec[i];
  }
  cout << ans << '\n';
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*

*/
ll N;
bool is_sorted(ll G[])
{
  rep(i, N-1){
    if (G[i] > G[i+1]) return false;
  }
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll T;
  cin >> T;
  rep(i, T){
    cin >> N;
    ll G[N];
    ll cnt = 0;
    vector<ll> ans;
    rep(j, N) cin >> G[j];
    while (!is_sorted(G)){
      ll tmp = -1;
      if (cnt%2 == 0){
        for(ll k=0; k+1<N; k+=2){
          if (G[k] < G[k+1]) continue;
          tmp = k;
        }
        if (tmp == -1) tmp = 0;
      }
      if (cnt%2 == 1){
        for(ll k=1; k+1<N; k+=2){
          if (G[k] < G[k+1]) continue;
          tmp = k;
        }
        if (tmp == -1) tmp = 1;
      }
      swap(G[tmp], G[tmp+1]);
      ans.push_back(tmp+1);
      cnt++;
    }
    ll asz = ans.size();
    cout << asz << endl;
    rep(j, asz){
      cout << ans[j];
      if (j == asz-1) cout << endl;
      else cout << " ";
    }
  }
}
