#include<bits/stdc++.h>
using  namespace  std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'
 #define mod 1000000007
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
//        ll ans=0;
//        for(ll i=b;i>=a+a;i--)
//        {
//            ll x=i-2*a +1;
//            ans+=x;
//        }
//        cout<<ans<<nl;
        ll ans=0;
        ll x=2*a;
        if(b>=x)
        {
            x=b-x+1;
            ans+=x*(x+1)/2;
        }
        cout<<ans<<nl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

void solve(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    rep(i,n) --p[i];

    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_a(0, n-2);

    int m = 0;
    vector<int> ans;
    while(1){
        bool change = false;
        rep(i,n-1){
            if(abs(i-m)%2==0 && p[i] > p[i+1]){
                swap(p[i],p[i+1]);
                ans.push_back(i);
                change = true;
                ++m;
                break;
            }
        }

        bool ok = true;
        rep(i,n) if(p[i] != i) ok = false;
        if(ok) break;

        if(!change && !ok){
            int ind = n-2;
            if(abs(ind-m)%2==1) ind--;
            swap(p[ind],p[ind+1]); 
            ans.push_back(ind);
            ++m;
        }
    }

    cout << m << endl;
    rep(i,m) cout << ans[i]+1 << " ";
    cout << endl;
    return;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}