#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int> output(n,0);
        if(n%2==0)
        {
            for(int i=0;i<n;i++)
                if(i%2==0)
                    output[i] = i+2;
                else
                {
                    output[i] = i;
                }
        }
        else
        {
            for(int i=0;i<n/2;i++)
            {
                output[i] = n - i;
            }
            output[n/2 - 1] =  n/2 + 2;
            output[n/2] = n/2;
            output[n/2 + 1] = n/2 + 1;
            for(int i=n/2+2;i<n;i++)
                output[i] = n-i;
        }
        for(auto x:output)
            cout<<x<<" ";
        cout<<endl;
    }
    return 0;
}