process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        const result = new Array(test).fill(0);

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            if (i < 0) {
                return;
            }

            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            addNumber(test - 1);
            addNumber(test - 2);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
        }

        // DESC order
        let k = 1;
        for (let j = 1; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

"use strict";var m=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of f(e))!d.call(r,n)&&n!==t&&m(r,n,{get:()=>e[n],enumerable:!(s=p(e,n))||s.enumerable});return r};var g=r=>h(m({},"__esModule",{value:!0}),r);var w={};b(w,{main:()=>l});module.exports=g(w);var o=class{constructor(){this.lines=[];this.data="";process.stdin.resume(),process.stdin.setEncoding("utf-8"),this.complete=new Promise((e,t)=>{process.stdin.on("data",s=>this.data+=s),process.stdin.on("end",()=>{this.lines=this.data.split(`
`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:""}readInt(){return parseInt(this.readLine())}readInts(e=" "){return this.readLine().split(e).map(t=>parseInt(t))}},a=class{writeln(e){process.stdout.write(e),process.stdout.write(`
`)}};function c(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}l(new o,new a);async function l(r,e){await r.complete;let t=r.readInt();for(let s=0;s<t;s++){let n=r.readInt(),u=c(1,n);for(let i=n-4;i>=0;i-=2)u.splice(i,2,...u.slice(i,i+2).reverse());e.writeln(u.join(" "))}}0&&(module.exports={main});

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    const ans = Array(n)
    for (let i = 1; i <= n; i++) {
        // if (n & 1) {
        //     // ans[i - 1] = i + 1
        // } else {
            ans[i - 1] = n - 1 - i
        // }
    }
    if (n & 1) {
        [ans[0], ans[1]] = [ans[1], ans[0]]
    }
    ans[n - 3] = 1
    ans[n - 2] = n - 1
    ans[n - 1] = n
    // ;[ans[0], ans[n - 3]] = [ans[n - 3], ans[0]]
    // console.log(check(ans))
    return ans.join(' ')
}
function check(arr) {
    return arr.reduce((s, x) => s < x ? s + x : 0, 0)
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk;
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let z=1;z<=t;z++)
    {
        let n=parseInt(line[z]);
        let ans='';
        if(n&1)
        {
            ans+=1+' ';
            for(let i=n-2;i>=2;i--) ans+=i+' ';
        }
        else
        {
            for(let i=n-2;i>=1;i--) ans+=i+' ';
        }
        ans+=(n-1)+' '+n;
        console.log(ans);
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk;
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let z=1;z<=t;z++)
    {
        let n=parseInt(line[z]);
        // console.log(n);
        let ans='';
        if(n&1)
        {
            ans+=1+' ';
            for(let i=n-2;i>=2;i--) ans+=i+' ';
        }
        else
        {
            for(let i=n-2;i>=1;i--) ans+=i+' ';
        }
        ans+=(n-1)+' '+n;
        console.log(ans);
    }
})

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const getresult = (n) => {
    let perm = Array(n).fill().map((_, i) => i+1 )

    let i = n % 2
    while(i < n - 2)
    {
        [ perm[i], perm[i + 1] ] = [ perm[i + 1], perm[i] ]

        i += 2
    }

    return perm.join(' ')
}

function main() {
    let testcases = parseInt( readline() )

    while( testcases-- ){
        let n = parseInt( readline() )
        console.log( getresult(n) )
    }
}
//*/

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
})

let i = 0
rl.on('line', function (line) {
  i++
  if (i > 1) {
    // console.log('--->', line);
    processLine(line)
  }
})

function processLine (line) {
  const n = Number(line)
  const arr = new Array(n)
  arr[n - 1] = n
  arr[n - 2] = n - 1
  arr[n - 3] = 1
  let i = 0
  const odd = (n % 2) | 0
  if (odd) { arr[0] = 2; i = 1 };
  for (let el = n - 2; el >= 2 + odd; el--) {
    arr[i] = el
    i++
  }
  console.log(arr.join(' '))
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        const n = parseInt(readLine())
        if (n % 2 === 0) {
            for (let i = n - 2; i > 0; i --) {
                process.stdout.write(i.toString() + " ")
            }
        } else {
            process.stdout.write(`${n-3} ${n-2} `)
            for (let i = n - 4; i > 0; i --) {
                process.stdout.write(i.toString() + " ")
            }
        }
        console.log(`${n-1} ${n}`)
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', stdin => inputString += stdin);

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(s => s.trim());
    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        if (n % 2 === 0) {
            let suffix = [n-1, n];
            let prefix = [];
            let rem = (n - 2) / 2;
            for (let i = 0; i < rem; i++) {
                prefix.push(2*i+2);
                prefix.push(2*i+1);
            }
            let result = [...prefix, ...suffix].join(' ');
            output(result);
        } else {
            let prefix = [1,2,3];
            let suffix = [n-1, n];
            let rem = (n - 5) / 2;
            for (let i = 2; i < rem + 2; i++) {
                prefix.push(2*i+1);
                prefix.push(2*i);
            }
            let result = [...prefix, ...suffix].join(' ');
            output(result);
        }
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var n = Number(lines[i]);
        var ans = '';
        for(j = n - 3; j > 1; j--){
            ans += j + ' ';
        }
        ans += (n - 2) + ' ' + 1 + ' ' + (n - 1) + ' ' + n;
        console.log(ans);
    }
});

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/problem/1728/B/solution.ts
var solution_exports = {};
__export(solution_exports, {
  main: () => main
});
module.exports = __toCommonJS(solution_exports);

// src/lib/arrays.ts
function range(start, stop) {
  return Array.from(Array(stop - start + 1).keys()).map((it) => it + start);
}
function sliceReverse(array, start, count) {
  array.splice(start, count, ...array.slice(start, start + count).reverse());
}

// src/lib/codeforces.ts
var StdInput = class {
  constructor() {
    this.lines = [];
    this.data = "";
    process.stdin.resume();
    process.stdin.setEncoding("utf-8");
    this.complete = new Promise((resolve, reject) => {
      process.stdin.on("data", (it) => this.data += it);
      process.stdin.on("end", () => {
        this.lines = this.data.split("\n");
        resolve();
      });
    });
  }
  readLine() {
    var _a;
    return (_a = this.lines.shift()) != null ? _a : "";
  }
  readInt() {
    return parseInt(this.readLine());
  }
  readInts(sep = " ") {
    return this.readLine().split(sep).map((it) => parseInt(it));
  }
};
var StdOutput = class {
  writeln(line) {
    process.stdout.write(line);
    process.stdout.write("\n");
  }
};

// src/problem/1728/B/solution.ts
main(new StdInput(), new StdOutput());
async function main(input, output) {
  await input.complete;
  const T = input.readInt();
  for (let t = 0; t < T; t++) {
    const n = input.readInt();
    const p = range(1, n);
    for (let i = n - 4; i >= 0; i -= 2) {
      sliceReverse(p, i, 2);
    }
    output.writeln(p.join(" "));
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  main
});

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/problem/1728/B/solution.ts
var solution_exports = {};
__export(solution_exports, {
  main: () => main
});
module.exports = __toCommonJS(solution_exports);

// src/lib/codeforces.ts
var StdInput = class {
  constructor() {
    this.lines = [];
    this.data = "";
    process.stdin.resume();
    process.stdin.setEncoding("utf-8");
    this.complete = new Promise((resolve, reject) => {
      process.stdin.on("data", (it) => this.data += it);
      process.stdin.on("end", () => {
        this.lines = this.data.split("\n");
        resolve();
      });
    });
  }
  readLine() {
    var _a;
    return (_a = this.lines.shift()) != null ? _a : "";
  }
  readInt() {
    return parseInt(this.readLine());
  }
  readInts(sep = " ") {
    return this.readLine().split(sep).map((it) => parseInt(it));
  }
};
var StdOutput = class {
  writeln(line) {
    process.stdout.write(line);
    process.stdout.write("\n");
  }
};

// src/lib/natural-numbers.ts
function range(start, stop) {
  return Array.from(Array(stop - start + 1).keys()).map((it) => it + start);
}

// src/problem/1728/B/solution.ts
main(new StdInput(), new StdOutput());
async function main(input, output) {
  await input.complete;
  const T = input.readInt();
  for (let t = 0; t < T; t++) {
    const n = input.readInt();
    const p = range(1, n);
    for (let i = n - 4; i >= 0; i -= 2) {
      p.splice(i, 2, ...p.slice(i, i + 2).reverse());
    }
    output.writeln(p.join(" "));
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  main
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        const result = new Array(test).fill(0);

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            if (i < 0) {
                return;
            }

            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            addNumber(test - 2);
            addNumber(test - 1);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
        }

        // DESC order
        let k = 1;
        for (let j = 1; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        const result = new Array(test).fill(0);

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            addNumber(x - 2);
            addNumber(x - 1);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
        }

        // DESC order
        let k = 1;
        for (let j = 1; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        const result = new Array(test).fill(0);

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            addNumber(x - 1);
            addNumber(x - 2);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
        }

        // DESC order
        let k = 1;
        for (let j = 1; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            // Phase 3
            let k = test;
            for (let j = 1; j <= test; j++) {
                while (added.has(k)) {
                    k--;
                }

                addNumber(k);
            }
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
            // Phase 3
            let k = 1;
            for (let j = 1; j <= test; j++) {
                while (added.has(k)) {
                    k++;
                }

                addNumber(k);
            }
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            addNumber(test - 2);
        }

        // Phase 3
        let k = test;
        for (let j = 1; j <= test; j++) {
            while (added.has(k)) {
                k--;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
        }

        // Phase 3
        let k = test;
        for (let j = 0; j <= test; j++) {
            while (added.has(k)) {
                k--;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            // Phase 3
            let k = test;
            for (let j = 0; j <= test; j++) {
                while (added.has(k)) {
                    k--;
                }

                addNumber(k);
            }
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            // Phase 3
            let k = 1;
            for (let j = 0; j <= test; j++) {
                while (added.has(k)) {
                    k++;
                }

                addNumber(k);
            }
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
            addNumber(1);
            // Phase 3
            let k = 1;
            for (let j = 0; j <= test; j++) {
                while (added.has(k)) {
                    k++;
                }

                addNumber(k);
            }
        } else {
            // Odd case
            addNumber(test - 1);
            addNumber(1);
            // Phase 3
            let k = test;
            for (let j = 0; j <= test; j++) {
                while (added.has(k)) {
                    k--;
                }

                addNumber(k);
            }
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 1) {
            console.log('1');
            continue;
        }

        if (test === 2) {
            console.log('1 2');
            continue;
        }

        if (test === 3) {
            console.log('2 1 3');
            continue;
        }

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
        } else {
            // Odd case
            addNumber(test - 1);
        }

        addNumber(1);

        // Phase 3
        let k = test;
        for (let j = 0; j <= test; j++) {
            while (added.has(k)) {
                k--;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 1) {
            console.log('1');
            continue;
        }

        if (test === 2) {
            console.log('1 2');
            continue;
        }

        if (test === 3) {
            console.log('2 1 3');
            continue;
        }

        if (test === 4) {
            console.log('2 1 3 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
        } else {
            // Odd case
            addNumber(test - 1);
        }

        addNumber(1);

        // Phase 3
        let k = 1;
        for (let j = 0; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        const result = new Array(test).fill(0);

        if (test === 1) {
            console.log('1');
            continue;
        }

        if (test === 2) {
            console.log('1 2');
            continue;
        }

        if (test === 3) {
            console.log('2 1 3');
            continue;
        }

        if (test === 4) {
            console.log('3 1 2 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
        } else {
            // Odd case
            addNumber(test - 1);
        }

        addNumber(1);

        // Phase 3
        let k = 1;
        for (let j = 0; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n').map(Number);
    for (let testNumber = 1; testNumber < data.length; testNumber++) {
        const test = data[testNumber];
        console.log(test);
        const result = new Array(test).fill(0);

        if (test === 1) {
            console.log('1');
            continue;
        }

        if (test === 2) {
            console.log('1 2');
            continue;
        }

        if (test === 3) {
            console.log('2 1 3');
            continue;
        }

        if (test === 4) {
            console.log('3 1 2 4');
            continue;
        }

        let i = result.length - 1;
        const added = new Set();
        const addNumber = (num) => {
            result[i] = num;
            added.add(num);
            i--;
        };

        // Phase 1
        addNumber(test);

        // Phase 2
        if (test % 2 === 0) {
            // Even case
            const x = Math.floor((test - 2) / 2);
            const y = x + 1;
            addNumber(y);
            addNumber(x);
        } else {
            // Odd case
            addNumber(test - 1);
        }

        addNumber(1);

        // Phase 3
        let k = 1;
        for (let j = 0; j <= test; j++) {
            while (added.has(k)) {
                k++;
            }

            addNumber(k);
        }

        console.log(result.join(' '));
    }
});

"use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var f=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},b=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!d.call(r,s)&&s!==t&&u(r,s,{get:()=>e[s],enumerable:!(n=l(e,s))||n.enumerable});return r};var h=r=>b(u({},"__esModule",{value:!0}),r);var g={};f(g,{main:()=>c});module.exports=h(g);var i=class{constructor(){this.lines=[];this.data="";process.stdin.resume(),process.stdin.setEncoding("utf-8"),this.complete=new Promise((e,t)=>{process.stdin.on("data",n=>this.data+=n),process.stdin.on("end",()=>{this.lines=this.data.split(`
`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:""}readInt(){return parseInt(this.readLine())}readInts(e=" "){return this.readLine().split(e).map(t=>parseInt(t))}},o=class{writeln(e){process.stdout.write(e),process.stdout.write(`
`)}};function m(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}c(new i,new o);async function c(r,e){await r.complete;let t=r.readInt();for(let n=0;n<t;n++){let s=r.readInt(),a=m(1,s);a.splice(-4,2,...a.slice(-4,-2).reverse()),e.writeln(a.join(" "))}}0&&(module.exports={main});

"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var t in e)a(r,t,{get:e[t],enumerable:!0})},f=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of l(e))!p.call(r,i)&&i!==t&&a(r,i,{get:()=>e[i],enumerable:!(n=c(e,i))||n.enumerable});return r};var b=r=>f(a({},"__esModule",{value:!0}),r);var h={};d(h,{main:()=>m});module.exports=b(h);var s=class{constructor(){this.lines=[];this.data="";process.stdin.resume(),process.stdin.setEncoding("utf-8"),this.complete=new Promise((e,t)=>{process.stdin.on("data",n=>this.data+=n),process.stdin.on("end",()=>{this.lines=this.data.split(`
`),e()})})}readLine(){var e;return(e=this.lines.shift())!=null?e:""}readInt(){return parseInt(this.readLine())}readInts(e=" "){return this.readLine().split(e).map(t=>parseInt(t))}},o=class{writeln(e){process.stdout.write(e),process.stdout.write(`
`)}};function u(r,e){return Array.from(Array(e-r+1).keys()).map(t=>t+r)}m(new s,new o);async function m(r,e){await r.complete;let t=r.readInt();for(let n=0;n<t;n++){let i=r.readInt();e.writeln(u(1,i).join(" "))}}0&&(module.exports={main});

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    const ans = Array(n)
    for (let i = 1; i <= n; i++) {
        ans[i - 1] = i
    }
    ;[ans[0], ans[n - 3]] = [ans[n - 3], ans[0]]
    return ans.join(' ')
}

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const getresult = (n) => {
    let res = []
    let i = 1
    while( i <= n ) {
        res.push(i)
        i++
    }

    return res.join(' ')
}

function main() {
    let testcases = parseInt( readline() )

    while( testcases-- ){
        let n = parseInt( readline() )

        console.log( getresult(n) )
    }

}
//*/

const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
})

let i = 0
rl.on('line', function (line) {
  i++
  if (i > 1) {
    // console.log('--->', line);
    processLine(line)
  }
})

function processLine (line) {
  const n = Number(line)
  const arr = new Array(n)
  arr[n - 1] = n
  arr[n - 2] = n - 1
  arr[n - 3] = 1
  let i = 0
  if (n % 2 === 0) {
    for (let el = n - 2; el >= 2; el--) {
      arr[i] = el
      i++
    }
  } else {
    for (let el = 2; el <= n - 2; el++) {
      arr[i] = el
      i++
    }
  }
  console.log(arr.join(' '))
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        const n = parseInt(readLine())
        if (n === 1) {
            console.log(1)
            continue
        }
        for (let i = n - 2; i > 0; i --) {
            process.stdout.write(i.toString() + " ")
        }
        console.log(`${n-1} ${n}`)
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', stdin => inputString += stdin);

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(s => s.trim());
    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        if (n % 2 === 0) {
            let suffix = [n-1, n];
            let prefix = [];
            let rem = (n - 2) / 2;
            for (let i = 0; i < rem; i++) {
                prefix.push(2*i+2);
                prefix.push(2*i+1);
            }
            let result = [...prefix, ...suffix].join(' ');
            output(result);
        } else {
            let prefix = [1,2,3];
            let suffix = [n-1, n];
            let rem = (n - 5) / 2;
            for (let i = 2; i < rem; i++) {
                prefix.push(2*i+1);
                prefix.push(2*i);
            }
            let result = [...prefix, ...suffix].join(' ');
            output(result);
        }
    }
}


var ints = function() {
	return readline().split(' ').map(function(word) {
		return parseInt(word)
	})
}

var n = parseInt(readline()),
	minEA = 1000000001,
	minEB = 1000000001,
	maxSA = 0,
	maxSB = 0,
	pair = []

while (n > 0) {
	pair = ints()
	minEA = Math.min(minEA, pair[1])
	maxSA = Math.max(maxSA, pair[0])
	n --
}

n = parseInt(readline())
while (n > 0) {
	pair = ints()
	minEB = Math.min(minEB, pair[1])
	maxSB = Math.max(maxSB, pair[0])
	n --
}

print(Math.max(0, Math.max(maxSB - minEA, maxSA - minEB)))

var classes = [
    {
        minEnd: 1000000000,
        maxStart: 1
    },
    {
        minEnd: 1000000000,
        maxStart: 1
    }
];
var maxDistance = 0;

for (var i = 0; i < classes.length; i++) {
    var amount = parseInt(readline());

    for (var j = 0; j < amount; j++) {
        var input = readline();

        var startTime = parseInt(input.split(" ")[0]);
        var endTime = parseInt(input.split(" ")[1]);

        if (classes[i].minEnd > endTime)
            classes[i].minEnd = endTime;
        if (classes[i].maxStart < startTime)
            classes[i].maxStart = startTime;
    }
}

if (classes[0].minEnd < classes[1].maxStart)
    maxDistance = classes[1].maxStart - classes[0].minEnd;
if (classes[1].minEnd < classes[0].maxStart)
    if (maxDistance < classes[0].maxStart - classes[1].minEnd)
        maxDistance = classes[0].maxStart - classes[1].minEnd;

print(maxDistance);

var contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];

for(var i = 0; i < contVal.length; i++) {

    var num_pairs = parseInt(readline());

    for(var j = 0; j < num_pairs; j++) {

        var pair = readline().split(' ').map(Number);

        contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);
        contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);
    }
}

print(Math.max(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r)));

/*
    The idea to solve this problem is basically observing the condition how rest time is formed:
    - l1->r1 l2->r2
    - l2->r2 l1->r1

    Since we want to get maximum rest time, then we need to compare these two conditions:
    - l1->r1 l2->r2 ==> max(l2) - min(r1)
    - l2->r2 l1->r1 ==> max(l1) - min(r2)

    Notice that when period is intersect (the resulted value from formula above will negative), based on problem description, the value of distance will become 0. Thus above formula will be like this:
    - l1->r1 l2->r2 ==> max(0, max(l2) - min(r1))
    - l2->r2 l1->r1 ==> max(0, max(l1) - min(r2))

    Thus to get max distance, the formula would be: max(max(0, max(l2) - min(r1)), max(0, max(l1) - min(r2)))
*/

// define container for containing max l & min r values
var contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];

// search for max l & min r value
for(var i = 0; i < contVal.length; i++) {

    var num_pairs = parseInt(readline());

    for(var j = 0; j < num_pairs; j++) {

        var pair = readline().split(' ').map(Number);

        contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);
        contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);
    }
}

// get max distance | rest time
print(Math.max(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r)));

var n = parseInt(readline());
  var np = [];
  var nsrm = - Infinity;
  var nslm = Infinity;
  var nerm = - Infinity;
  var nelm = Infinity;
  while(n > 0) {
    np.push(readline().split(' ').map(function(x) { return parseInt(x); }));
    nsrm = Math.max(nsrm, np[np.length - 1][0]);
    nslm = Math.min(nslm, np[np.length - 1][0]);
    nerm = Math.max(nerm, np[np.length - 1][1]);
    nelm = Math.min(nelm, np[np.length - 1][1]);
    n -= 1;
  }

  var m = parseInt(readline());
  var mp = [];
  var msrm = - Infinity;
  var mslm = Infinity;
  var merm = - Infinity;
  var melm = Infinity;
  while(m > 0) {
    mp.push(readline().split(' ').map(function(x) { return parseInt(x); }));
    msrm = Math.max(msrm, mp[mp.length - 1][0]);
    mslm = Math.min(mslm, mp[mp.length - 1][0]);
    merm = Math.max(merm, mp[mp.length - 1][1]);
    melm = Math.min(melm, mp[mp.length - 1][1]);
    m -= 1;
  }
  print(Math.max(0, Math.max(nsrm - melm, msrm - nelm)));

var ints = function() {
	return readline().split(' ').map(function(word) {
		return parseInt(word)
	})
}

var n = parseInt(readline()),
	minEA = 1000000001,
	minEB = 1000000001,
	maxSA = 0,
	maxSB = 0,
	pair = []

while (n > 0) {
	pair = ints()
	minEA = Math.min(minEA, pair[1])
	maxSA = Math.max(maxSA, pair[0])
	n --
}

n = parseInt(readline())
while (n > 0) {
	pair = ints()
	minEB = Math.min(minEB, pair[1])
	maxSB = Math.max(maxSB, pair[0])
	n --
}

print(Math.max(maxSB - minEA, maxSA - minEB))

var contVal = [{max_l: -Infinity, min_r: +Infinity}, {max_l: -Infinity, min_r: +Infinity}];

for(var i = 0; i < contVal.length; i++) {

    var num_pairs = parseInt(readline());

    for(var j = 0; j < num_pairs; j++) {

        var pair = readline().split(' ').map(Number);

        contVal[i].max_l = Math.max(contVal[i].max_l, pair[0]);
        contVal[i].min_r = Math.min(contVal[i].min_r, pair[1]);
    }
}

print(Math.max(0, contVal[1].max_l - contVal[0].min_r), Math.max(0, contVal[0].max_l - contVal[1].min_r));


process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const [n, m, p] = readInts(input, 0)
  const ai = readInts(input, 1)
  const bi = readInts(input, 2)
  let i = 0, j =0
  while(i < n) {
    if(ai[i] % p !== 0) {
      break
    }
    i++
  }
  while(j < m) {
    if(bi[j] % p !== 0) {
      break
    }
    j++
  }
  // wr(i, j)
  wr(i + j)
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let s="",o=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(o=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{s+=t})),process.stdin.on("end",(e=>{o=s.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return o[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runMain((function(){let[t,e,r]=i.default.nextNumbers(),n=i.default.nextNumbers(),s=i.default.nextNumbers();i.default.puts(n.findIndex((t=>t%r!=0))+s.findIndex((t=>t%r!=0)))}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, m, p] = io.nextNumbers()
//   let a = io.nextNumbers()
//   let b = io.nextNumbers()
//
//   io.puts(a.findIndex((x) => x % p != 0) + b.findIndex((x) => x % p != 0))
// }
//
// // io.runEachTest(main)
// io.runMain(main)

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const [n, m, p] = readInts(input, 0)
  const ai = readInts(input, 1)
  const bi = readInts(input, 2)
  let i = 0, j =0
  while(i < n) {
    if(ai[i] % p !== 0 && i !== 0) {
      break
    }
    i++
  }
  while(j < m) {
    if(bi[j] % p !== 0 && j !== 0) {
      break
    }
    j++
  }
  wr(i, j)
  wr(i + j)
}

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const [n, m, p] = readInts(input, 0)
  const ai = readInts(input, 1)
  const bi = readInts(input, 2)
  let i = 0, j =0
  while(i < n) {
    if(ai[i] % p !== 0 && i !== 0) {
      break
    }
    i++
  }
  while(j < m) {
    if(bi[j] % p !== 0 && j !== 0) {
      break
    }
    j++
  }
  // wr(i, j)
  wr(i + j)
}


var inputMN = readline().split(" ").map(function (x) { return parseInt(x); });
var inputMList = readline().split(" ").map(function (x) { return parseInt(x); });
var inputNList = readline().split(" ").map(function (x) { return parseInt(x); });
var mOdd = 0, mEven = 0, nOdd = 0, nEven = 0;
for (var i = 0; i < inputMN[0]; i++) {
if (inputMList[i] % 2 === 0) {
  ++mEven;
} else {
  ++mOdd;
}
}
for (var j = 0; j < inputMN[1]; j++) {
if (inputNList[j] % 2 === 0) {
  ++nEven;
} else {
  ++nOdd;
}
}
print(Math.min(mEven, nOdd) + Math.min(nEven, mOdd));

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var line = read.arrNumber(' ');
    var n = line[0];
    var m = line[1];

    var a = read.arrNumber(' ');
    var b = read.arrNumber( ' ');

    var ac = 0;
    for(var i = 0; i < n; i ++) {
        if(a[i]%2 === 0) {
            ac++;
        }
    }
    var an = n - ac;

    var bc = 0;
    for(var i = 0; i < m; i ++) {
        if(b[i] % 2 === 0) {
            bc++;
        }
    }

    var bn = m - bc;

    var m1 = ac > bn ? bn : ac;
    var m2 = an > bc ? bc : an;
    print(m1 + m2);
}());

var firstLine = readline();

var cN = readline().split(' ');
var cM = readline().split(' ');

var cNObj = checkArr(cN);
var cMObj = checkArr(cM);

var res1 = Math.min(cNObj['ch'], cMObj['neCh']);
var res2 = Math.min(cNObj['neCh'], cMObj['ch']);

print(res1+res2);

function minVal(a, b) {

}
function checkArr(arr) {
    var chCount = 0;
    var neChCount = 0;
    arr.forEach(function(el) {
      if(el%2) {
          neChCount++;
      } else {
          chCount++;
      }
    });
    return {"ch" : chCount, "neCh" : neChCount};
}

readline();

var chests = readline().split(' ').map(function(num) {
  return parseInt(num);
});

var keys = readline().split(' ').map(function(num) {
  return parseInt(num);
});

var evenChestsAmount = 0;
var oddChestsAmount = 0;

var evenKeysAmount = 0;
var oddKeysAmount = 0;

for (var i = 0; i < chests.length; i++) {
  if (chests[i] % 2 == 0) {
    evenChestsAmount++;
  } else {
    oddChestsAmount++;
  }
}

for (var i = 0; i < keys.length; i++) {
  if (keys[i] % 2 == 0) {
    evenKeysAmount++;
  } else {
    oddKeysAmount++;
  }
}

var result = Math.min(evenChestsAmount, oddKeysAmount);
result += Math.min(oddChestsAmount, evenKeysAmount);

print(result);

var nm = readline().split(' ').map(v=>(parseInt(v)))
var chests = readline().split(' ').map(v=>(parseInt(v)%2 === 0))
var keys = readline().split(' ').map(v=>(parseInt(v)%2 === 0))

var min0 = Math.min(chests.filter(c=>(c)).length, keys.filter(k=>(!k)).length)
var min1 = Math.min(chests.filter(c=>(!c)).length, keys.filter(k=>(k)).length)

var res = min0 + min1;

print(res)

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let n, m;
let chests;
let keys;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  if (c === 1) {
    chests = d.split(' ').map(Number);
  }

  if (c === 2) {
    keys = d.split(' ').map(Number);
  }

  c++;
});

rl.on('close', () => {
  let odd = 0;
  let even = 0;
  let ans = 0;

  for (let i = 0; i < chests.length; i++) {
    if (chests[i] % 2 === 0) {
      even++;
    }
    else {
      odd++;
    }
  }

  for (let i = 0; i < keys.length; i++) {
    if (keys[i] % 2 !== 0 && even > 0) {
      even--;
      ans++;
    }
    else if (keys[i] % 2 === 0 && odd > 0) {
      odd--;
      ans++;
    }
  }

  console.log(ans);
});

ip= readline().split(' ');
n = +ip[0], m = +ip[1];
one = readline().split(' ').map(Number).reduce(((acc,x)=>x%2 === 1?acc+1:acc),0);
two = readline().split(' ').map(Number).reduce(((acc,x)=>x%2 === 1?acc+1:acc),0);
print(Math.min(one,m - two) + Math.min(two,n - one));


var input = readline().split(" ");
var prices = [];
for (var i = 0; i < parseInt(input[0],10); i++) {
    prices.push(readline());
}
var min = prices[0].split(" ")[0]/prices[0].split(" ")[1];
for (var i = 1; i < prices.length; i++) {
    var temp = prices[i].split(" ")[0]/prices[i].split(" ")[1];
    if (temp < min) min = temp;
}
write(min*input[1]);

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		var tmp = nextIntArray();
		list[i] = tmp[0] / tmp[1];
	}
	list.sort(function(a,b){
		return a - b;
	});
	myout(list[0] * M);
}

'use strict';

function Scanner() {
  this.nextLine = () => readline();
  this.nextInt = () => parseInt(readline());
  this.nextDouble = () => parseInt(readline());
  this.nextArray = () => readline().split(' ');
}

const is = new Scanner();

let line = is.nextArray().map(Number);
let n = line[0];
let m = line[1];
let a, b;

let answer = Infinity;
for (let i = 0; i < n; i++) {
  line = is.nextArray().map(Number);
  a = line[0];
  b = line[1];
  answer = Math.min(answer, (a * m) / b);
}

print(answer);

// http://codeforces.com/problemset/problem/977/A
module.exports = solve;
function solve() {
    var [n, m] = readline();
    var min = 999999;
    for (var i = 0; i < n; i++) {
        const [a, b]= readline();
        min = Math.min(min, a / b)
    }
    return min * m;
}

function readline(){
    return lines.shift();
}
const lines = [];
const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
rl.on('line', (line) => {
    lines.push(line.split(' ').map(n => parseInt(n, 10)));
    if(lines.length -1 === lines[0][0]) {
        console.log(solve());
        rl.close();
    }
});

'use strict';
var inputData = readline().split(' ');
var n = parseInt(inputData[0]);
var m = parseInt(inputData[1]);
var cost = [];
for (var i = 0; i < n; i++) {
    var input = readline().split(' ');
    var a = parseInt(input[0]);
    var b = parseInt(input[1]);
    cost.push(a / b);
}
print(Math.min.apply(Math, cost) * m);

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let n, m;
let best = Infinity;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  let [a, b] = d.split(' ').map(Number);
  let tmp = (m * a / b);

  if (tmp < best) {
    best = tmp;
  }

  c++;
});

rl.on('close', () => {
  console.log(best.toFixed(8));
});

// http://codeforces.com/problemset/problem/977/A
module.exports = solve;
function solve(vals) {
    let min = 99999999;
    vals.forEach(v => {
        let [a, b] = line.split(' ').map(n => parseInt(n, 10));
        min = Math.min(b/a, min);
    })
    return min;
}

const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

let vals = [];
rl.on('line', (line) => {
    vals.push(line);
    // if (i++) {
        // /console.log(solve(line))
        // rl.close();
    // }
});
rl.on('end', (line) => {
    console.log(solve(vals))
})

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let n, m;
let best = Infinity;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  let [a, b] = d.split(' ').map(Number);
  let tmp = (m * a / b).toFixed(8);

  if (tmp < best) {
    best = tmp;
  }

  c++;
});

rl.on('close', () => {
  console.log(best);
});


var t=readline();
while(t--)
{
  var n=readline();
  print(n + " ");

  for(var i=1;i<=n-1;i++)
  {
      print(i + " ");
  }
  print("\n");
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    A();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t){
        t--;
        let n = pi(readline());
        let res = '';
        for(let i = 1; i <= n; i++){
            if(i !== n){
                res += ` ${i+1}`;
            }else{
                res += ` ${1}`;
            }
        }

        console.log(res.trim());
    }
}

function main(){
    var n = readline();
    for(var i = 0; i < n; ++i){
        var num = readline();
        var res = '';
        res += `${num} `;
        for(var j = 1; j < num - 1; ++j){
            res += `${j} `;
        }
        res += num - 1;
        print(res);
    }
}

main();

'use strict'

let t = readline();

while(t--)
{
   let n = readline(), a = [];
   for(let i = 1; i < n; i++)a[i] = i;
   a[0] = n;
   print(a.join(" "));
}

(function() {
    var t = +readline()

    for (var i = 0; i < t; i++) {
        var n = +readline()
        var arr = []
        flag = true
        for (j = 1; j <= n; j++) {
            if (j + 1 <= n) {
                arr.push(j + 1)
            } else {
                arr.push(j - j + 1)
            }

        }
        print(arr.join(' '))
    }
}())

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];
  var part = l/2;

  for (var j = 1; j <= l; j++) {
    res[j-1] = j;
  }

   for (var k = 0; k < l -1; k++) {

       var temp = res[k];
       res[k] = res[k+1];
       res[k+1] = temp;

   }

  print(res.toString().replace(/\,/g, ' '));
}

var start = true

function task(s){
	s = s.trim().split('\n')
	let t = +s.shift()
	for (let i = 0; i < t; i++) {
		let n = +s.shift(), a = []
		for (let j = n; j>=1; j--) {
			a.push(j)
			if(j==a.length){
				a[a.length-1] = n
				a[0] = j
			}
		}
		console.log(a.join(' '));
	}
}

if(start){
	process.stdin.resume();
	process.stdin.setEncoding('utf-8');
	let inputString = '';
	process.stdin.on('data', inputStdin => {
	    inputString += inputStdin;
	});
	process.stdin.on('end', _ => {
	    task(inputString);
	});
}

const solve = (p) => {
    let res = [];
    for (let i = 1; i <= p; i++) {
        res.unshift(i);
    }
    if (p % 2 == 1) {
        let mid = p >> 1;
        [res[mid], res[mid + 1]] = [res[mid + 1], res[mid]];
    }
    console.log(res.join(" "));
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = Number(input[0][0]);
        let i = 1;
        while (t > 0) {
            let data = input.slice(i, i + 1);
            solve(data[0][0]);
            t--;
            i++;
        }
    });
};

main()

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const ans = [];

    for (let i = 2; i <= len; i++) ans.push(i);
    ans.push(1);

    console.log(ans.join(" "));
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = new Array(N);
		for(var j = 1; j <= N; j++){
			list[j - 1] = j;
		}
		list.push(list.shift());
		output[i] = myconv(list, 8);
	}
	myout(myconv(output, 9));
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = new Array(N);
		for(var j = 1; j <= N; j++){
			list[j - 1] = j;
		}
		list.push(list.shift());
		myout(myconv(list, 8));
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
      // const s = data[i].trim().split(' ');
      // let a = data[i].trim() * 1;
      const n = data[i] * 1;
      // const p = BigInt(s[0]);
      // const q = BigInt(s[1]);
      // s.sort((a, b) => b - a);
      let arr = [];
      // console.log(p%q)
      // let first = true;
      // for (let j = p; j > 0; j -= 1n) {
      //   if (p % j === 0n && j % q !== 0n) {
      //     console.log(j.toString());
      //     break;
      //   } else if (first) {j = j / 2n + 1n; first = false;}
      // }
      let j = n;
      while (j > Math.ceil(n / 2)) {
        arr.push(j);
        j -= 1;
      }
      j = 1;
      while (j <= Math.ceil(n / 2)) {
        arr.push(j);
        j += 1;
      }
      console.log(arr.join(' '));
      i += 1;
    }
}

"use strict";

(() => {

    const readline = require('readline').createInterface({
        input: process.stdin,
        output: process.stdout
    });

    let curLine = 0, allLines = [];

    let nextLine = () => {
        if(curLine == allLines.length) throw new ReferenceError("No more input in the buffer");
        return allLines[curLine++]
    };

    readline.on("line", line => { allLines.push(line); });
    readline.on("close", () => { main(nextLine) });

})();

function main(nextLine) {
    let t = Number(nextLine());

    while(t--) {
        let n = Number(nextLine());

        let ans = [];
        for(let i = 2; i <= n; i++) ans.push(i);
        ans.push(1);

        console.log(ans.join(" "));
    }
}

/* this language fucking sucks */

const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

let lines = [];

rl.on('line', (data) => {
    lines.push(data);
    if(lines.length > 0 && parseInt(lines[0]) === lines.length - 1) {
	rl.close();
	main();
    }
});

async function main() {
    let t = parseInt(lines[0]);
    for(let i = 1; i <= t; i++) {
	let n = parseInt(lines[i]);
	let ans = n + ' ';
	for(let j = 1; j < n; j++) {
	    ans += (j + ' ');
	}
	console.log(ans);
    }
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let i="",s=[],u=0,l="";const a="local"===process.argv[2],h=t=>{if(a){if(s=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{s=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function p(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=p();for(;e>0;)t(),e--}))},readline:f,nextNumbers:p,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(p());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=p();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312));function i(t){for(var e,r,n=t.length;0!==n;)r=Math.floor(Math.random()*n),e=t[n-=1],t[n]=t[r],t[r]=e;return t}o.default.runEachTest((function(){let[t]=o.default.nextNumbers(),e=[];for(let r=1;r<=t;++r)e.push(r);for(;;){e=i(e);let r=!0;for(let n=1;n<=t;++n)if(e[n-1]==n){r=!1;break}if(r)break}o.default.puts(e.join(" "))}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function shuffle(array) {
//   var currentIndex = array.length,
//     temporaryValue,
//     randomIndex
//
//   // While there remain elements to shuffle...
//   while (0 !== currentIndex) {
//     // Pick a remaining element...
//     randomIndex = Math.floor(Math.random() * currentIndex)
//     currentIndex -= 1
//
//     // And swap it with the current element.
//     temporaryValue = array[currentIndex]
//     array[currentIndex] = array[randomIndex]
//     array[randomIndex] = temporaryValue
//   }
//
//   return array
// }
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let a: number[] = []
//
//   for (let i = 1; i <= n; ++i) {
//     a.push(i)
//   }
//
//   while (true) {
//     a = shuffle(a)
//
//     let ok = true
//
//     for (let i = 1; i <= n; ++i) {
//       if (a[i - 1] == i) {
//         ok = false
//         break
//       }
//     }
//
//     if (ok) {
//       break
//     }
//   }
//
//   io.puts(a.join(" "))
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);

    let values = lines.map(val => parseInt(val));
    let t = values[0];

    for (let i = 0; i < t; i++) {
        console.log(solve(values[i + 1]));
    }
});

function solve(n) {
    const result = [];

    for (let i = 2; i <= n; i++) {
        result.push(i);
    }

    result.push(1);

    return result.join(' ');
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

/*
    2
    5

        2 1
        2 1 5 3 4
*/

function aaa(n) {
    n = +n;
    // console.log(n);

    let A = [];
    for (let i=0; i<n; i++) {
    	A[i] = i+1;
    }

    for (let i=1; i<n; i+=2) {
    	[A[i-1], A[i]] = [A[i], A[i-1]];
    }

    if (n%2 !== 0) {
    	// odd
    	let i = n-1;
    	[A[i-1], A[i]] = [A[i], A[i-1]];
    }

    console.log(A.join(" "));
    return A;
}

let T;
let A = [];

let i = 0;
// multi line input
readline.on('line', line => {

    if (i === 0) {
        T = line;
        i++;
        return
    } else {
        aaa(line);
    }
});

function main(){
    var n = readline();
    for(var i = 0; i < n; ++i){
        var num = readline();
        var res = '';
        for(var j = num; j > 1; --j){
            res += `${j} `;
        }
        res += '1';
        print(res);
    }
}

main();

function main(){
    var n = readline();
    for(var i = 0; i < n; ++i){
        var num = readline();
        var res = '';
        res += '5 ';
        for(var j = 1; j < num - 1; ++j){
            res += `${j} `;
        }
        res += num - 1;
        print(res);
    }
}

main();

function main(){
    var n = readline();
    for(var i = 0; i < n; ++i){
        var num = readline();
        var res = '';
        res += `${n} `;
        for(var j = 1; j < num - 1; ++j){
            res += `${j} `;
        }
        res += num - 1;
        print(res);
    }
}

main();

(function() {
    var t = +readline()

    for (var i = 0; i < t; i++) {
        var n = +readline()
        var arr = []
        for (j = 1; j <= n; j++) {
            arr.push(j)
        }
        print(arr.join(' '))
    }
}())

(function() {
    var t = +readline()

    for (var i = 0; i < t; i++) {
        var n = +readline()
        var arr = []
        var flag = false
        for (j = 1;j <= n; j++) {
            if (flag) {
                arr.push(j)
                flag = false
            } else {
                arr.push(100 - j + 1)
                 flag = true
            }
        }
        var res = arr.join(' ')
        print(res)
    }

}())

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];
  var num;

  for (var j = 1; j <= l; j++) {
    num = 1;

    if (num != j) {
      while (~res.indexOf(num)) {
        num++;
      }
      res[j-1] = num;
    } else {
      num++;
      while (~res.indexOf(num)) {
        num++;
      }

      res[j-1] = num;
    }
  }

    print(res.toString().replace(/\,/g, ' '));
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  for (var j = 0; j < l; j++) {
    res[j] = j+1;
  }

    print(res.toString().replace(/\,/g, ' '));
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  for (var j = 0; j < l; j++) {
    res[j] = j+1;
  }
    print(res.slice(0,2).reverse().concat(res.slice(2).reverse()).toString().replace(/\,/g, ' '));
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  for (var j = 0; j < l; j++) {
    res[j] = j+1;
  }

    print(res.reverse().toString().replace(/\,/g, ' '));
}

const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

async function cin() {
    return new Promise((resolve, reject) => {
	rl.question('', (data) => {
	    resolve(data);
	});
    });
}

async function cint() {
    let n = await cin();
    return parseInt(n);
}

async function main() {
    let t = await cint();
    while(t--) {
	let n = await cint();
	process.stdout.write(n + ' ');
	for(let i = 1; i < n; i++) {
	    process.stdout.write(i + ' ');
	}
	process.stdout.write('\n');
    }

    rl.close();
}

main();

const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

async function cin() {
    return new Promise((resolve, reject) => {
	rl.question('', (data) => {
	    resolve(data);
	});
    });
}

async function cint() {
    let n = await cin();
    return parseInt(n);
}

async function main() {
    let t = await cint();
    while(t--) {
	let n = await cint();
	let ans = n + ' ';
	for(let i = 1; i < n; i++) {
	    ans += (i + ' ');
	}
	console.log(ans);
    }

    rl.close();
}

main();

const rl = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

async function cin() {
    return new Promise((resolve, reject) => {
	rl.on('line', (data) => {
	    resolve(data);
	});
    });
}

async function cint() {
    let n = await cin();
    return parseInt(n);
}

async function main() {
    let t = await cint();
    while(t--) {
	let n = await cint();
	let ans = n + ' ';
	for(let i = 1; i < n; i++) {
	    ans += (i + ' ');
	}
	console.log(ans);
    }

    rl.close();
}

main();

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

/*
    2
    5

        2 1
        2 1 5 3 4
*/

function aaa(n) {
    n = +n;
    // console.log(n);

    let A = [];
    for (let i=0; i<n; i++) {
    	A[i] = i+1;
    }

    for (let i=1; i<n; i+=2) {
    	[A[i-1], A[i]] = [A[i], A[i-1]];
    }

    if (n%2 !== 0) {
    	// odd
    	let i = n-1;
    	[A[i-1], A[i]] = [A[i], A[i-1]];
    }

    console.log(A);
    return A;
}

let T;
let A = [];

let i = 0;
// multi line input
readline.on('line', line => {

    if (i === 0) {
        T = line;
        i++;
        return
    } else {
        aaa(line);
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    A();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t){
        t--;
        let n = pi(readline());
        let res = '';
        for(let i = 1; i <= n; i++){
            if(i !== n){
                res += ` ${i+1}`;
            }else{
                res += ` ${i+1}`;
            }
        }

        console.log(res.trim());
    }
}