Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.You have to calculate the number of different sequences of $$$4$$$ digits that could be the password for Monocarp's mobile phone (i. e. these sequences should meet all constraints on Monocarp's password).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$) — the number of digits for which Monocarp remembers that they were not used in the password. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots a_n$$$ ($$$0 \le a_i \le 9$$$) representing the digits that were not used in the password. Note that the digits $$$a_1, a_2, \dots, a_n$$$ are given in ascending order.

For each testcase, print one integer — the number of different $$$4$$$-digit sequences that meet the constraints.

NoteIn the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".

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];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
            if(n == 1){
                console.log(216);
            }
            if(n == 2){
                console.log(168);
            }
            if(n == 3){
                console.log(126);
            }
            if(n == 4){
                console.log(90);
            }
            if(n == 5){
                console.log(60);
            }
            if(n == 6){
                console.log(36);
            }
            if(n == 7){
                console.log(18);
            }
            if(n == 8){
                console.log(6);
            }
        }
    }
});

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var n = readline();
    var digits = 10 - readline().split(' ').length;
    console.log(digits * (digits - 1) * 3);
  }
}

/*
** Template
*/

// 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 //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    // let primes = sivOfAtkin(1000)
    while (t--) {
        let n = parseInt(readline())
        let arr = readline().split(' ').map(Number)
        console.log( 3 * ( 10 - n ) * ( 9 - n ) )
    }
}
// Driver Function Ends //

/*
* auther yeling
*
*
*/
'use strict';

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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, nums) {
    let left = 10 - n;
    let sum = left * (left - 1) / 2 * 6;
    print(sum);
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var x = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, x);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function main() {

    let t = parseInt(readLine());

    while(t--)
    {
        const n = parseInt(readLine());

        const arr_a = readLine().split(" ").map(x=>parseInt(x));

        let done = new Set()

        //console.log("arr_a " +arr_a)

        let nums = [0,1,2,3,4,5,6,7,8,9]
        let second_arr = nums.filter(n => !arr_a.includes(n))
        //console.log("second_arr" + second_arr)
        for(const a of second_arr)
        {
            //console.log("a " +a)
            for(const b of second_arr.slice())
            {
                if(a==b)
                    continue;
                //console.log("b " +b)
                 done.add(a.toString()+a.toString()+b.toString()+b.toString())
                 done.add(a.toString()+b.toString()+a.toString()+b.toString())
                 done.add(a.toString()+b.toString()+b.toString()+a.toString())
            }
        }
        //console.log(Array(...done).join(' '))
        console.log(done.size)

    }
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  rn();
        const a = rns();
  const set = new Set(a.map(String));
  let res = 0;
  for (let i = 0; i < 10000; i++) {
    const s = i.toString().padStart(4, '0').split('');
    const cnt = new Map();
    for (let i = 0; i < s.length; i++) {
      var _cnt$get;
      cnt.set(s[i], ((_cnt$get = cnt.get(s[i])) !== null && _cnt$get !== void 0 ? _cnt$get : 0) + 1);
    }
    if (cnt.size !== 2) continue;
    const [a, b] = [...cnt.keys()];
    if (set.has(a) || set.has(b)) continue;
    if (cnt.get(a) !== 2 || cnt.get(b) !== 2) continue;
    res++;
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let k = 10 - n;
    k = (k * (k - 1)) / 2;
    console.log(k * 6);
  }
};
solve();

var testCasesCount = parseInt(readline());
var i = 0;
for (i = 0; i < testCasesCount; i++) {
  var exclusionLength = parseInt(readline());
  var excludedNums = readline().split(' ');
  var includedCount = 10 - excludedNums.length;
  print(((includedCount) * (includedCount - 1) / 2) * 6);
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var totalExcluded = parseInt(readline());
    readline();
    var value = 10 - totalExcluded
    var result = 6 * (value * (value-1) / 2);
    print(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];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
            if(n == 1){
                console.log(216);
            }
            if(n == 8){
                console.log(6)
            }
        }
    }
});


You are given $$$n$$$ words of equal length $$$m$$$, consisting of lowercase Latin alphabet letters. The $$$i$$$-th word is denoted $$$s_i$$$.In one move you can choose any position in any single word and change the letter at that position to the previous or next letter in alphabetical order. For example:  you can change 'e' to 'd' or to 'f';  'a' can only be changed to 'b';  'z' can only be changed to 'y'. The difference between two words is the minimum number of moves required to make them equal. For example, the difference between "best" and "cost" is $$$1 + 10 + 0 + 0 = 11$$$.Find the minimum difference of $$$s_i$$$ and $$$s_j$$$ such that $$$(i < j)$$$. In other words, find the minimum difference over all possible pairs of the $$$n$$$ words.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 50$$$, $$$1 \leq m \leq 8$$$) — the number of strings and their length respectively. Then follows $$$n$$$ lines, the $$$i$$$-th of which containing a single string $$$s_i$$$ of length $$$m$$$, consisting of lowercase Latin letters.

For each test case, print a single integer — the minimum difference over all possible pairs of the given strings.

6

2 4

best

cost

6 3

abb

zba

bef

cdu

ooo

zzz

2 7

aaabbbc

bbaezfe

3 2

ab

ab

ab

2 8

aaaaaaaa

zzzzzzzz

3 1

a

u

y

NoteFor the second test case, one can show that the best pair is ("abb","bef"), which has difference equal to $$$8$$$, which can be obtained in the following way: change the first character of the first string to 'b' in one move, change the second character of the second string to 'b' in $$$3$$$ moves and change the third character of the second string to 'b' in $$$4$$$ moves, thus making in total $$$1 + 3 + 4 = 8$$$ moves.For the third test case, there is only one possible pair and it can be shown that the minimum amount of moves necessary to make the strings equal is $$$35$$$.For the fourth test case, there is a pair of strings which is already equal, so the answer is $$$0$$$.

/*
File Created: Tuesday, 17 May 2022
Author: Lukas Rimkus
*/
'use strict';

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

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
     data += chunk;
});
process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '').split('\n').map(str => str.replace(/\s*$/, ''));
    let testCases = parseInt(readLine());
    while(testCases--) {
        const [n,m] =  get_ints();
        const obj = {};
        for (let index = 0; index < n; index++) {
            obj[index] = readLine();
        }
        console.log(solve([n,m,obj]));
    }
});
function get_ints() {
    return data[currentLine++].split(' ').map(x=>Number(x));
}

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

function solve(input){
    let min = Number.MAX_SAFE_INTEGER;
    let w1;
    let w2;
    for(let i = 0; i < input[0] - 1; i++){
        w1 = Object.values(input[2])[i].split('').map(str => str.charCodeAt());
        for(let j = i + 1; j < input[0]; j++){
            w2 = Object.values(input[2])[j].split('').map(str => str.charCodeAt());
            let diff = 0;
            for(let m = 0; m < input[1]; m++){
                diff += Math.abs(w1[m] - w2[m])
            }
            if(min > diff){
                min = diff;
            }
        }
    }
    return min;
}

module.exports = solve;

'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, m] = readline().split(' ').map(Number);
        let S = [];
        const alphabet = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));
        const letterPos = {};
        alphabet.forEach((letter, i) => letterPos[letter] = i + 1);

        for (let i = 0; i < n; i++) {
            S[i] = readline().split('').map(l => letterPos[l]);
        }

        let min = Infinity;

        for (let i = 0; i < n; i++) {
            let localMin = Infinity;

            for (let j = 0; j < n; j++) {
                if (i === j) continue;
                let sum = 0;
                for (let k = 0; k < m; k++) {
                    sum += Math.abs(S[i][k] - S[j][k]);
                }
                localMin = Math.min(localMin, sum);
            }

            min = Math.min(min, localMin);
        }

        output(min);
    }
}

const { createInterface } = require('readline');
const max = Number.MAX_SAFE_INTEGER

function calcDiff(a, t) {
  let diff = max;
  for (let j = 0; j < t.length - 1; j++) {
    const b = t[j]
    let tempDiff = 0;
    for (let i = 0; i < a.length; i++) {
      tempDiff += Math.abs(a.charCodeAt(i) - b.charCodeAt(i))

    } if (tempDiff < diff) {
      diff = tempDiff
    }
  }
  return diff
}

function main() {
  const readline = createInterface({
    input: process.stdin,
    output: process.stdout
  });
  let lineNb = 0;
  let subLine = 0;
  let n;
  let minDiff = max;
  let subN;
  let t = [];

  readline.on('line', line => {
    if (!lineNb) {
      lineNb++
      n = parseInt(line);
    } else {
      const data = line.split(" ")
      if (data.length == 2) {
        diff = max;
        subLine = 0;
        lineNb++
        minDiff = max
        subN = data[0]
        t = []
      } else {
        subLine++;
        t.push(data[0])
        if (subLine > 1) {
          const res = calcDiff(t[subLine - 1], t)
          if (minDiff > res) {
            minDiff = res
          }
        }
        if (subLine == subN) {
          console.log(minDiff)
          if (lineNb == n + 1) {
            readline.close()
          }
        }
      }
    }

  });

}

main()

function diff(a, b) {
    var x = 0;
    for (let i = 0; i < a.length; i++) {
        x += Math.abs(a.charCodeAt(i) - b.charCodeAt(i));
    }
    return x;
}

function solve(inp) {
  var t = Number(inp.nextLine());
  while(t--) {
    const [n, m] = inp.nextLine().split(" ").map(x => Number(x));
    const arr = new Array(n);
    for (let i = 0; i < n; i++) {
        arr[i] = inp.nextLine();
    }

    var min = Number.MAX_SAFE_INTEGER;
    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            min = Math.min(min, diff(arr[i], arr[j]));
        }
    }
    console.log(min);
  }
}

class Input {
    constructor(lines) {
        this.lines = lines;
        this.next = 0;
    }

    addLine(line) {
        this.lines.push(line)
    }

    hasLine() {
       return this.lines.size() > 0;
    }

    nextLine() {
        const line = this.lines[this.next];
        if (line) {
            this.next++;
        }
        return line;
    }
}

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

const inp = new Input([]);

readline.on('line', line => {
    inp.addLine(line);
});

readline.on('close', () => {
    solve(inp);
});

const solve = (arr,n,l) => {
     let min = Infinity,cnt;
     for(let i=0;i<n;i++){
          for(let j=i+1;j<n;j++){
                cnt = 0;
               for(let k=0;k<l;k++) cnt+=Math.abs(arr[i][k].charCodeAt()-arr[j][k].charCodeAt());
               if(cnt<min) min = cnt;
          }
     }
     return min;
};
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let n = parseInt(readline());
  for(let i=0;i<n;i++){
       let [l,k] = readline().split(" ").map(cur=>parseInt(cur));
       let arr = [];
       for(let j=0;j<l;j++){
            arr.push(readline());
       }
       console.log(solve(arr,l,k));
  }
}
main();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, m, s) {
  let res = Infinity;
  for (let i = 0; i < n; i++) {
    for (let j = i + 1; j < n; j++) {
      let cur = 0;
      for (let k = 0; k < m; k++) {
        if (s[i][k] === s[j][k]) continue;
        cur += Math.abs(s[i].charCodeAt(k) - s[j].charCodeAt(k));
      }
      res = Math.min(res, cur);
    }
  }
  return res.toString();
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const [n, m] = (await read()).split(' ').map(Number);
    const a = [];
    let tmp = n;
    while (tmp--) {
      a.push(await read());
    }
    res.push(solve(n, m, a));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

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

const wordDistance = (one, two) => {
  return one
    .map((ch, i) => Math.abs(ch.charCodeAt(0) - two[i].charCodeAt(0)))
    .reduce((a, b) => a + b, 0);
};

let lines = 0;

let words = [];
const findMinimumDistance = (words) => {
  let minimumDistance = 100000000;
  for (let i = 0; i < words.length - 1; i++) {
    const one = words[i].split("");
    for (let j = i + 1; j < words.length; j++) {
      const two = words[j].split("");
      const distance = wordDistance(one, two);
      // console.log(distance);
      if (minimumDistance > distance) {
        minimumDistance = distance;
      }
    }
  }
  console.log(minimumDistance);
};
rl.on("line", function (line) {
  if (lines !== 0) {
    if (line.split(" ").length === 2) {
      if (words.length > 0) {
        findMinimumDistance(words);
      }
      words = [];
    } else {
      words.push(line);
    }
  }
  lines++;
});

rl.on("close", function (line) {
  findMinimumDistance(words);
});

'use strict';

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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, m] = input().split(' ').map(Number);
    const s = [];
    for(let i = 0; i < n; i++){
      s.push(input());
    }
    let ans = Number.POSITIVE_INFINITY;
    for(let i = 0; i < n; i++){
      for(let j = i+1; j < n; j++){
        ans = Math.min(ans, solve(s[i], s[j], m));
      }
    }
    console.log(ans);
  }
}

const solve = (s1, s2, m) => {
  let ret = 0;
  for(let i = 0; i < m; i++){
    let tmp = Number.POSITIVE_INFINITY;
    const [c1, c2] = [s1[i], s2[i]];
    tmp = Math.min(tmp, Math.abs(c1.charCodeAt(0)-c2.charCodeAt(0)), Math.abs(c2.charCodeAt(0)-c1.charCodeAt(0)));
    ret += tmp;
  }
  return ret;
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var q=1;q<=T;q++) {
  var [n, x] = readline().split(' ').map((x)=>parseInt(x));
  var a = []
  for(var i=0;i<n;i++) {
    var s = readline();
    a.push(s);
  }
  var ans = 1000000000;
  var f = alph();
  var m = new Map();
  for(var i=0;i<f.length;i++) {
    m.set(f[i], i);
  }
  var len = a.length;
  for(var i=0;i<len;i++) {
    for(var j=i+1;j<len;j++) {
      var tar = 0;
      for(var t=0;t<x;t++) {
        tar += max(m.get(a[i][t])-m.get(a[j][t]), m.get(a[j][t])-m.get(a[i][t]));
      }
      ans = min(ans, tar);
    }

  }
  console.log(ans);
  //fs.appendFileSync('output.txt', ans+'\r\n');

  //os.EOL
}
//fs.writeFileSync('output.txt', f.join(' '));

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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;}}

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
	const n = nextInt();
    const numOfChars = nextInt();
    const stringArr = nextStrArray(n);

    let min = Infinity;
    for (let i = 0; i < stringArr.length; i++) {
        for (let j = i + 1; j < stringArr.length; j++){
            const s1 = stringArr[i];
            const s2 = stringArr[j];
            let sum = 0;
            for (let k = 0; k < numOfChars; k++) {
                sum += Math.abs(s1[k].charCodeAt(0) - s2[k].charCodeAt(0));
            }
            min = Math.min(min, sum)
        }
    }

    myout(min)
}

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, m] = lines[l++].trim().split(' ').map(Number)
        const arr = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let ans = Infinity
    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            ans = Math.min(ans, cal(arr, i, j))
        }
    }
    return ans
}
function cal(arr, p, q) {
    let ans = 0
    for (let i = 0; i < arr[0].length; i++) {
        const a = arr[p].charCodeAt(i)
        const b = arr[q].charCodeAt(i)
        const d = Math.abs(a - b)
        // if (arr[p] === 'a' || arr[q] === 'a') {
            ans += d
        // } else if (arr[p] === 'z' || arr[q] === 'z') {
        //     ans += d
        // } else {
        //     ans += Math.min(d, 26 - d)
        // }
    }
    // console.log(arr[p], arr[q], ans)
    return ans
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, m] = ra();
  let S = [];
  for (let i=0; i<n; i++)
    S.push(readline());
  LT({n, m, S});
  // PROCESSING:
  let ans = 0;
  let min = Infinity;
  let dist = (s1, s2)=>{
    let d = 0;
    for (let i=0; i<m; i++){
      let ch1 = s1.charCodeAt(i);
      let ch2 = s2.charCodeAt(i);
      d += Math.abs(ch1-ch2);
    }
    return d;
  };
  for (let i=0; i<n; i++){
    for (let j=0; j<n; j++){
      if (i!=j) min = Math.min(min, dist(S[i], S[j]))
    }
  }
  return min;
};

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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 alpha = "abcdefghijklmnopqrstuvwxyz";
	while(hasNext()){
		var N = nextInt();
		var M = nextInt();
		var list = nextStrArray(N);
		var output = 100000000;
		for(var i = 0; i < N; i++){
			for(var j = i + 1; j < N; j++){
				var L = list[i];
				var R = list[j];
				var diff = 0;
				for(var k = 0; k < M; k++){
					diff += Math.abs(alpha.indexOf(L[k]) - alpha.indexOf(R[k]));
				}
				output = Math.min(output, diff);
			}
		}
		myout(output);
	}
}

t = parseInt(readline());
for(i = 0; i < t; i++)
{
    var n = readline().split(" ");
    n[0] = parseInt(n[0]);
    n[1] = parseInt(n[1]);
    var strings = [];
    for(j = 0; j < n[0]; j++)
    {
        strings[j] = readline();
    }
    var min = 201;
    var diff = 0;
    for(j = 0; j < n[0] - 1; j++)
    {
        for(k = j + 1; k < n[0]; k++)
        {
            diff = 0;
            for(l = 0; l < n[1]; l++)
            {
                diff += Math.abs(strings[j].charCodeAt(l) - strings[k].charCodeAt(l));
            }
            if(diff < min) min = diff;
        }
    }
    print(min);
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], m = _a[1];
    var a = [];
    a.length = n;
    for (var i = 0; i < n; i++)
        a[i] = (readline().split('').map(function (v) { return v.charCodeAt(0); }));
    var min = 1000000;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < i; j++) {
            var sum = 0;
            for (var k = 0; k < m; k++) {
                sum += Math.abs(a[i][k] - a[j][k]);
            }
            min = Math.min(min, sum);
        }
    }
    print(min);
}

/*
File Created: Tuesday, 17 May 2022
Author: Lukas Rimkus
*/
'use strict';

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

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
     data += chunk;
});
process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '').split('\n').map(str => str.replace(/\s*$/, ''));
    let testCases = parseInt(readLine());
    while(testCases--) {
        const [n,m] =  get_ints();
        const obj = {};
        for (let index = 0; index < n; index++) {
            obj[index] = readLine();
        }
        console.log(solve([n,m,obj]));
    }
});
function get_ints() {
    return data[currentLine++].split(' ').map(x=>Number(x));
}

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

function solve(input){
    let min;
    let w1;
    let w2;
    for(let i = 0; i < input[0] - 1; i++){
        w1 = Object.values(input[2])[i].split('').map(str => str.charCodeAt());
        for(let j = i + 1; j < input[0]; j++){
            w2 = Object.values(input[2])[j].split('').map(str => str.charCodeAt());
            let diff = 0;
            for(let m = 0; m < input[1]; m++){
                diff += Math.abs(w1[m] - w2[m])
            }
            if(!min || min > diff){
                min = diff;
            }
        }
    }
    return min;
}

module.exports = solve;


Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n).

Print m integers — the answers to the queries in the order in which they are given in the input.

var s = 'a' + readline();

var n = +readline();

var a = [ 0 ];
var c = 0;

for( var i = 1; i < s.length; i++ )
	a[ i ] = s[ i ] === s[ i-1 ] ? ++c : c;

var ans = [];
while( n-- ){
	readline().split(' ').reduce(function(l, r){
		ans.push( a[ r ] - a[ l ] );
	});
}
print( ans.join( '\n' ) );

var s = 'a' + readline();

var n = +readline();

var a = [ 0 ];
var c = 0;

for( var i = 1; i < s.length; i++ )
	a[ i ] = s[ i ] === s[ i-1 ] ? ++c : c;

while( n-- ){
	readline().split(' ').reduce(function(l, r){
		print( a[ r ] - a[ l ] );
	});
}

var arr = readline().split('');

var dp = new Array(arr.length);
dp[dp.length-1]=0;

for(var i=arr.length-2; i>=0; i--){
  if(arr[i]===arr[i+1])
    dp[i]=dp[i+1]+1;
  else
    dp[i]=dp[i+1];
}

var x=parseInt(readline());

while(x--){
  var a = readline().split(' ').map(a => parseInt(a));
  print(dp[a[0]-1]-dp[a[1]-1]);
}

var ps = new Array(1<<17);

for(var i=0;i<(1<<17);i++) {
  ps[i]=0;
}

var a = readline();
var n = a.length;

for(var i=1;i<n;i++) {
  if(a[i-1]==a[i]) {
    ps[i]=1;
  }

  ps[i]+=ps[i-1];
}

var q = readline();

while(q--) {
  var token = readline().split(' ');
  var l = token[0], r = token[1];

  print(ps[r-1]-ps[l-1]);
}

var s = readline();
var t = readline();
var a = [ 0 ];
var sum = 0;
for (var i = 1; i < s.length; i++) {
	if (s[i] === s[i - 1]) {
		sum++;
	}
	a.push(sum);
}
var ans = [];
for (var i = 0; i < t; i++) {
	var m = readline().split(' ').map((d) => parseInt(d));
	var tmp = a[m[1] - 1] - a[m[0] - 1];
	ans.push(tmp);
}
print(ans.join('\n'));

var s = readline();
var t = readline();
var a = [ 0 ];
var sum = 0;
for (var i = 1; i < s.length; i++) {
	if (s[i] === s[i - 1]) {
		sum++;
	}
	a.push(sum);
}

for (var i = 0; i < t; i++) {
	var m = readline().split(' ').map((d) => parseInt(d));
	var ans = a[m[1] - 1] - a[m[0] - 1];
	print(ans);
}

var m, current = 0, left, right;
var input = readline();
var charArray = input.split('');
var prefixSum = new Array(charArray.length);
prefixSum[0] = 0;
for (var i = 0; i < charArray.length - 1; i++) {
  if (charArray[i] == charArray[i + 1]) {
    current++;
  }
  prefixSum[i + 1] = current;
}

m = readline();

for (var i = 0; i < m; i++) {
  input = readline();
  left = Number(input.split(" ")[0]);
  right = Number(input.split(" ")[1]);
  print(prefixSum[right - 1] - prefixSum[left - 1]);
}

var myInput = readline();
var myLength = parseInt(readline());
var mySum = 0;
var sum_arr = [mySum];
for (var i = 1; i< myInput.length;i++){
    if (myInput[i-1] == myInput[i]){
        mySum += 1;
        sum_arr.push(mySum);
    }
    else{
        sum_arr.push(mySum);
    }
}
for (var j = 0;j < myLength; j++){
    var next = readline().split(' ').map((val)=>{
        return parseInt(val);
    });
    print(sum_arr[next[1]-1]-sum_arr[next[0]-1]);
}

;(function () {

	var s = readline();
	var n = +readline();

	s = '!' + s;
	var l = s.length;

	var b = [0];

	for( var i = 1; i < l; i++ )
		b.push( s[i] !== s[i-1] ? b[i - 1] : b[i - 1] + 1 );

	while(n--){
		print(readline().split(' ').reduce(function(first, second){
			return b[second] - b[first];
		}));
	}

}).call(this);

function main() {
    var line = readline();
    var n = line.length;
    var data = [];
    for(var i=0;i<n;i++){
        data[i] = line[i+1] == line[i] ? (data[i-1] || 0) + 1 : (data[i-1] || 0);
    }
    var m = Number(readline());
    for(var i=0;i<m;i++){
        var li = readline().split(' ').map(Number);
        var l = li[0];
        var r = li[1];
        print(data[r-2] - (data[l-2] || 0));
    }
}

main()

s=readline()
var A = new Array(s.length)
for (var i=0; i<s.length-1; ++i) {
 A[i] = Number(s[i]==s[i+1])
}
A[s.length-1]=0

var T = new Array(s.length+1)
T[0]=0
for (var i=1; i<=s.length; ++i)
 T[i]=T[i-1]+A[i-1]

var n=Number(readline())
for (var i=0;i<n;++i) {
 var In = readline().split(' ').map(Number)
 print(T[In[1]-1]-T[In[0]-1])
}

var input = readline().split('');
var eq = [];
var counter = 0;
eq[0] = 0;
for (var i = -1; i < input.length; i++) {
    if (input[i] == input[i-1]) counter++;
    eq[i] = counter;
}

var n = readline().split(' ').map(Number);
var res = '';
for (var i = 0; i < n; i++) {
    var line = readline().split(' ').map(Number);
    var a = line[0];
    var b = line[1];
    res = res + (eq[b-1] - eq[a-1]).toString() + '\n';
}
write(res);

var str = readline(),
    m = +readline(),
    l = [],
    r = [],
    data = [0];

for (var i = 1; i < str.length; i ++)
{
  data[i] = data[i - 1] + ((str[i] === str[i - 1]) ? 1 : 0);
}

for (var i = 0; i < m; i ++)
{
  var line = readline().split(' ');
  l[i] = +line[0] - 1;
  r[i] = +line[1] - 1;

  print(data[r[i]] - data[l[i]]);
}

var s = readline().split(''),
			m = readline(),
			pairCount = [ 0 ];

		s.forEach(function(c, i)	{
			var prevPairCount = pairCount[pairCount.length - 1];

			pairCount.push(c == s[i - 1] ? prevPairCount + 1 : prevPairCount);
		});

		for(var a=0; a<m; a++)	{
			var queryPair = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
				li = parseInt(queryPair[0]), ri = parseInt(queryPair[1]),
				queryResult = 0;

			print([ li, ri ].reduce(function(a, b)	{
				return pairCount[b] - pairCount[a];
			}));
		}

const input = [];

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

RL.on('line', line => input.push(line));

RL.on('close', () => {
  let s = input[0];
  const n =parseInt(input[1]);

  const map = []; let sum = 0;

  map[0] = 0;
  for (let i = 1; i < s.length; i += 1) {
    if (s[i-1] === s[i]) { sum += 1; }
      map[i] = sum;
  }

  //console.log(map);
  const answer = [];
  for (i = 0; i < n; i += 1) {
    const [left, right] = input[i + 2].split(' ').map(x => parseInt(x));
    answer.push(map[right-1] - map[left-1]);
    answer.push('\n');
  }

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

var s = readline().split(''),
    m = readline(),
    sQueryPair = {},
    query = [],
    result = [];

s.forEach(function(a, i)    {
    sQueryPair[i + 1] = a == s[i + 1] ? 1 : 0;
});

for(var a=0; a<m; a++)  {
    var queryPair = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
        queryResult = 0;

    query.push(queryPair);

    for(var i=queryPair[0]; i<queryPair[1]; i++)    {
        queryResult += sQueryPair[i];
    }

    result.push(queryResult);
}

result.forEach(function(row, index) {
    print(row);
});

var s = readline().split(''),
			m = readline(),
			sQueryPair = [ 0 ];

		s.forEach(function(a, i)	{
			var preVal = sQueryPair[sQueryPair.length - 1];

			sQueryPair.push(a == s[i + 1] ? preVal + 1 : preVal);
		});

		for(var a=0; a<m; a++)	{
			var queryPair = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
				li = parseInt(queryPair[0]), ri = parseInt(queryPair[1]),
				queryResult = 0;

			print(queryPair.reduce(function(a, b)	{
				return sQueryPair[b] - sQueryPair[a];
			}));
		}

var s = readline().split(''),
			m = readline(),
			sQueryPair = [ 0 ];

		s.some(function(a, i)	{
			var preVal = sQueryPair[sQueryPair.length - 1];

			if(i == s.length)	preVal++;

			sQueryPair.push(a == s[i + 1] ? preVal + 1 : preVal);
		});

		for(var a=0; a<m; a++)	{
			var queryPair = readline().replace(/\s{1,}/gi, ' ').split(/\s/),
				li = parseInt(queryPair[0]), ri = parseInt(queryPair[1]),
				queryResult = 0;

			print(queryPair.reduce(function(a, b)	{
				return sQueryPair[b] - sQueryPair[a];
			}));
		}


You are given an integer $$$n$$$. You have to construct a permutation of size $$$n$$$.A permutation is an array where each integer from $$$1$$$ to $$$s$$$ (where $$$s$$$ is the size of permutation) occurs exactly once. For example, $$$[2, 1, 4, 3]$$$ is a permutation of size $$$4$$$; $$$[1, 2, 4, 5, 3]$$$ is a permutation of size $$$5$$$; $$$[1, 4, 3]$$$ is not a permutation (the integer $$$2$$$ is absent), $$$[2, 1, 3, 1]$$$ is not a permutation (the integer $$$1$$$ appears twice).A subsegment of a permutation is a contiguous subsequence of that permutation. For example, the permutation $$$[2, 1, 4, 3]$$$ has $$$10$$$ subsegments: $$$[2]$$$, $$$[2, 1]$$$, $$$[2, 1, 4]$$$, $$$[2, 1, 4, 3]$$$, $$$[1]$$$, $$$[1, 4]$$$, $$$[1, 4, 3]$$$, $$$[4]$$$, $$$[4, 3]$$$ and $$$[3]$$$.The value of the permutation is the number of its subsegments which are also permutations. For example, the value of $$$[2, 1, 4, 3]$$$ is $$$3$$$ since the subsegments $$$[2, 1]$$$, $$$[1]$$$ and $$$[2, 1, 4, 3]$$$ are permutations.You have to construct a permutation of size $$$n$$$ with minimum possible value among all permutations of size $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. Then, $$$t$$$ lines follow. The $$$i$$$-th of them contains one integer $$$n$$$ ($$$3 \le n \le 50$$$) representing the $$$i$$$-th test case.

For each test case, print $$$n$$$ integers — the permutation of size $$$n$$$ with minimum possible value. If there are multiple such permutations, print any of them.

NoteIn the first example, the permutation $$$[1, 4, 3, 5, 2]$$$ is one of the possible answers; its value is $$$2$$$.In the second example, the permutation $$$[4, 1, 6, 2, 5, 3]$$$ is one of the possible answers; its value is $$$2$$$.

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 a = lines[i];
        var ans = 1 + ' ';
        for(j = 3; j <= a; j++){
            ans += j + ' ';
        }
        ans += 2;
        console.log(ans);
    }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var P = [];
		for(var i = 1; i <= N / 2; i++){
			P.push(i);
			P.push(N - i + 1);
		}
		if(N % 2 == 1){
			P.push(Math.ceil(N / 2));
		}
		myout(myconv(P, 8));
	}
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let i = 1,
      j = n,
      k = 1;
    let res = new Array(n).fill(0);
    while (i <= j) {
      if (i === j) res[i - 1] = k++;
      else {
        res[j - 1] = k++;
        res[i - 1] = k++;
      }
      i++;
      j--;
    }
    console.log(res.join(" "));
  }
};
solve();

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var n = readline();
    var res = [1];
    for (var i = n; i > 1; i--) {
      res.push(i);
      if (i == 2) {
        process.stdout.write(res.join(" ") + '\n');
      }
    }
  }
}

/*
** Template
*/

// 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 //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    // let primes = sivOfAtkin(1000)
    while (t--) {
        let n = parseInt(readline())
        // let arr = readline().split(' ').map(Number)
        console.log(solve(n))
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n) => {
    let res = ''
    let i = 1
	while(++i <= n)
	{
		res +=  ( i + ' ' )
	}

    res +=  1

    return res
}

function factorial(num) {
    let rval=1
    for (let i = 2; i <= num; i++)
        rval = rval * i
    return rval
}

function excludes(a, b) {
    let setB = new Set(b)
    return [...new Set(a)].filter(x => !setB.has(x))
}

function intersect(a, b) {
    let setB = new Set(b)
    return [...new Set(a)].filter(x => setB.has(x))
}

function gcd(a, b) {
    if (b == 0) return a
    return gcd(b, a % b)
}

const factors = number => Array.from(Array(number + 1), (_, i) => i).filter(i => number % i === 0)

function sivOfAtkin(limit) {
    let limitSqrt = Math.sqrt(limit)
    let sieve = new Array(limit + 1).fill(false)
    sieve[2] = sieve[3] = true

    let n = 0
    for (let x = 1; x <= limitSqrt; x++) {
        let xx = x * x
        for (let y = 1; y <= limitSqrt; y++) {
            let yy = y * y
            if (xx + yy >= limit) break

            // first quadratic using m = 12 and r in R1 = {r : 1, 5}
            n = (4 * xx) + (yy)
            if (n <= limit && (n % 12 == 1 || n % 12 == 5)) sieve[n] = !sieve[n]

            // second quadratic using m = 12 and r in R2 = {r : 7}
            n = (3 * xx) + (yy)
            if (n <= limit && (n % 12 == 7)) sieve[n] = !sieve[n]

            // third quadratic using m = 12 and r in R3 = {r : 11}
            n = (3 * xx) - (yy)
            if (x > y && n <= limit && (n % 12 == 11)) sieve[n] = !sieve[n]
        }
    }

    return sieve
}

const isOdd = (num) => num & 1
const isEven = (num) => !(num & 1)
const minOfArray = (arr) => Math.min.apply(null, arr)
const maxOfArray = (arr) => Math.max.apply(null, arr)
const uniqueArray = (arr) => [...new Set(arr)]
const sortArray = (arr) => arr.sort((a, b) => a - b)
const sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)

// cmd: cat input.txt | node main.js

/*
* auther yeling
*
*
*/
'use strict';

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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n) {
    if(n == 1) {
        print('1');
        return;
    }
    let res = new Array(n).fill(0);
    for(let i = 1; i < n; i++) {
        res[i] = i + 2;
    }
    res[0] = 1;
    res[n - 1] = 2;
    print(res.join(' '));
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        begin(n);
    }
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn();
  const res = [1];
  for (let i = 1; i < n; i++) {
    res[i] = n - i + 1;
  }
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    console.log(1, 4, 3, 5, 2);
    console.log(4, 1, 6, 2, 5, 3)
});

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 a = lines[i].split('').map(Number);
        var x = 0;
        var y = 0;
        for(j = 0; j < 6; j++){
            if(j >= 3){
                x += a[j];
            }else{
                y += a[j];
            }
        }
        console.log(x == y ? 'YES' : 'NO');
    }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var P = [];
		for(var i = 1; i <= N; i++){
			P.push(i);
		}
		for(var i = 1; i < N - 1; i += 2){
			var tmp = P[i];
			P[i] = P[i + 1];
			P[i + 1] = tmp;
		}
		myout(myconv(P, 8));
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
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 if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var P = [];
		for(var i = 1; i <= N; i += 2){
			P.push(i);
		}
		for(var i = 2; i <= N; i += 2){
			P.push(i);
		}
		myout(myconv(P, 8));
	}
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = [];
    for (let i = n; i >= 1; i--) arr.push(i);
    console.log(arr.join(" "));
  }
};
solve();


You are given a board of size $$$n \times n$$$, where $$$n$$$ is odd (not divisible by $$$2$$$). Initially, each cell of the board contains one figure.In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell $$$(i, j)$$$ you can move the figure to cells:   $$$(i - 1, j - 1)$$$;  $$$(i - 1, j)$$$;  $$$(i - 1, j + 1)$$$;  $$$(i, j - 1)$$$;  $$$(i, j + 1)$$$;  $$$(i + 1, j - 1)$$$;  $$$(i + 1, j)$$$;  $$$(i + 1, j + 1)$$$; Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. $$$n^2-1$$$ cells should contain $$$0$$$ figures and one cell should contain $$$n^2$$$ figures).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n < 5 \cdot 10^5$$$) — the size of the board. It is guaranteed that $$$n$$$ is odd (not divisible by $$$2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$ ($$$\sum n \le 5 \cdot 10^5$$$).

For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

'use strict';

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 => string.trim());

    main();
});

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

const addBigNumbers = (x, y) => {
    const a = [...x];
    a.reverse();
    const b = [...y];
    b.reverse();
    const res = [];
    const size = Math.max(a.length, b.length);

    for (let i = 0; i < size; i++) {
        const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);
        const cat = oof % 10;
        const rest = parseInt(oof / 10);

        res[i] = cat;
        res[i + 1] = rest;
    }

    res.reverse();

    return res[0] === 0 ? res.slice(1) : res;
};

function main() {
    const n = parseInt(readline());
    const arrays = [];
    for (let i = 0; i < n; i++) {
        arrays.push(parseInt(readline()));
    }

    arrays.forEach(a => {
        const size = parseInt(a / 2);
        let sumSmol = 0;
        let sum = [];

        for (let i = 0; i < size; i++) {
            const mic = 2 * i + 1;
            const mare = 2 * (i + 1) + 1;
            const gucciMic = (i + 1) * (mare * mare - mic * mic);
            if (i < 225000) {
                sumSmol += gucciMic;
            } else {
                const gucci = `${gucciMic}`.split('').map(o => parseInt(o));
                sum = addBigNumbers(sum, gucci);
            }
        }

        sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));

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

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++];
}

const store = {};

function main() {
	let t = +readLine();
	while (t--) {
		let n = +readLine();
		let s = 0n;

		while (n > 1) {
			s += BigInt(4 * (n - 1) * Math.floor(n / 2));
			n -= 2;
		}

		console.log(s.toString());
	}
}

'use strict';

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 => string.trim());

    main();
});

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

const addBigNumbers = (x, y) => {
    const a = [...x];
    a.reverse();
    const b = [...y];
    b.reverse();
    const res = [];
    const size = Math.max(a.length, b.length);

    for (let i = 0; i < size; i++) {
        const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);
        const cat = oof % 10;
        const rest = parseInt(oof / 10);

        res[i] = cat;
        res[i + 1] = rest;
    }

    res.reverse();

    return res[0] === 0 ? res.slice(1) : res;
};

function main() {
    const n = parseInt(readline());
    const arrays = [];
    for (let i = 0; i < n; i++) {
        arrays.push(parseInt(readline()));
    }

    arrays.forEach(a => {
        if (a === 1) {
            console.log(0);
        }

        const size = parseInt(a / 2);
        let sumSmol = 0;
        let sum = [];

        for (let i = 0; i < size; i++) {
            const mic = 2 * i + 1;
            const mare = 2 * (i + 1) + 1;
            const gucciMic = (i + 1) * (mare * mare - mic * mic);
            if (i < 225000) {
                sumSmol += gucciMic;
            } else {
                const gucci = `${gucciMic}`.split('').map(o => parseInt(o));
                sum = addBigNumbers(sum, gucci);
            }
        }

        sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));

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

'use strict';

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 => string.trim());

    main();
});

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

const addBigNumbers = (x, y) => {
    const a = [...x];
    a.reverse();
    const b = [...y];
    b.reverse();
    const res = [];
    const size = Math.max(a.length, b.length);

    for (let i = 0; i < size; i++) {
        const oof = (res[i] || 0) + (a[i] || 0) + (b[i] || 0);
        const cat = oof % 10;
        const rest = parseInt(oof / 10);

        res[i] = cat;
        res[i + 1] = rest;
    }

    res.reverse();

    return res[0] === 0 ? res.slice(1) : res;
};

function main() {
    const n = parseInt(readline());
    const arrays = [];
    const start = new Date();
    for (let i = 0; i < n; i++) {
        arrays.push(parseInt(readline()));
    }

    arrays.forEach(a => {
        if (a === 1) {
            console.log(0);
        }

        const size = parseInt(a / 2);
        let sumSmol = 0;
        let sum = [];

        for (let i = 0; i < size; i++) {
            const mic = 2 * i + 1;
            const mare = 2 * (i + 1) + 1;
            const gucciMic = (i + 1) * (mare * mare - mic * mic);
            if (i < 225000) {
                sumSmol += gucciMic;
            } else {
                const gucci = `${gucciMic}`.split('').map(o => parseInt(o));
                sum = addBigNumbers(sum, gucci);
            }
        }

        sum = addBigNumbers(sum, `${sumSmol}`.split('').map(o => parseInt(o)));

        console.log(sum.join(''));
    });
    const end = new Date();

    console.log(end - start);
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Each $$$a_i$$$ is one of the six following numbers: $$$4, 8, 15, 16, 23, 42$$$.Your task is to remove the minimum number of elements to make this array good.An array of length $$$k$$$ is called good if $$$k$$$ is divisible by $$$6$$$ and it is possible to split it into $$$\frac{k}{6}$$$ subsequences $$$4, 8, 15, 16, 23, 42$$$.Examples of good arrays:  $$$[4, 8, 15, 16, 23, 42]$$$ (the whole array is a required sequence);  $$$[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$$$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);  $$$[]$$$ (the empty array is good). Examples of bad arrays:   $$$[4, 8, 15, 16, 42, 23]$$$ (the order of elements should be exactly $$$4, 8, 15, 16, 23, 42$$$);  $$$[4, 8, 15, 16, 23, 42, 4]$$$ (the length of the array is not divisible by $$$6$$$);  $$$[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$$$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is one of the following numbers: $$$4, 8, 15, 16, 23, 42$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum number of elements you have to remove to obtain a good array.

// problem name: Lose it!
// problem link: https://codeforces.com/problemset/problem/1176/C
// contest link: https://codeforces.com/contest/1176
// author: reyad
// time: (?)

'use strict';

function main() {
	let n = nextInt();
	let count = [0, 0, 0, 0, 0, 0];
	// 4,8,15,16,23,42
	let pos = {
		4  : 0,
		8  : 1,
		15 : 2,
		16 : 3,
		23 : 4,
		42 : 5
	};

	let ans = 0;
	for(let i=0; i<n; i++) {
		let a = nextInt();
		let at = pos[a];
		if(at == 0) count[at]++;
		else {
			if(count[at-1] > 0) {
				count[at-1]--;
				count[at]++;
			}
			else ans++;
		}
	}

	for(let i=0; i<5; i++) {
		ans += (i+1) * count[i];
	}
	console.log(ans);
}

// reader and main caller

let readline = require('readline');

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

let inputBuf = [];
let inputBufCnt = 0;
let tk = []
let tkCnt = 0;

function nextLine() {
	return inputBuf[inputBufCnt++];
}
function next() {
	if(tkCnt == tk.length) {
		tk = inputBuf[inputBufCnt++].split(' ');
		tkCnt = 0;
	}
	return tk[tkCnt++];
}
function nextInt() {
	return parseInt(next());
}
function nextDouble() {
	return parseFloat(next());
}

rl.on('line', (line) => {
	inputBuf.push(line);
}).on('close', () => {
	main();
});


You are given a string $$$s$$$ such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of $$$s$$$ such that it contains each of these three characters at least once.A contiguous substring of string $$$s$$$ is a string that can be obtained from $$$s$$$ by removing some (possibly zero) characters from the beginning of $$$s$$$ and some (possibly zero) characters from the end of $$$s$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 20000$$$) — the number of test cases. Each test case consists of one line containing the string $$$s$$$ ($$$1 \le |s| \le 200000$$$). It is guaranteed that each character of $$$s$$$ is either 1, 2, or 3. The sum of lengths of all strings in all test cases does not exceed $$$200000$$$.

For each test case, print one integer — the length of the shortest contiguous substring of $$$s$$$ containing all three types of characters at least once. If there is no such substring, print $$$0$$$ instead.

NoteConsider the example test:In the first test case, the substring 123 can be used.In the second test case, the substring 213 can be used.In the third test case, the substring 1223 can be used.In the fourth test case, the substring 3221 can be used.In the fifth test case, there is no character 3 in $$$s$$$.In the sixth test case, there is no character 1 in $$$s$$$.In the seventh test case, the substring 3112 can be used.

function comp(a,b) { return a-b; }
function solve(str) {
    var one = 0, two = 0, three = 0, ans = 200005, d = 0, arr = [];
    for (var i in str) {
        if (str[i] == '1')
            one = i;
        else if (str[i] == '2')
            two = i;
        else
            three = i;

        if (one && two && three) {
            arr = [one,two,three];
            arr.sort(comp);
            d = arr[2]-arr[0]+1;
            ans = Math.min(ans,d);
        }
    }
    print(ans == 200005 ? 0 : ans);
}
var t = Number(readline());
while (t--) {
    var str = readline();
    solve(str);
}

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i <= Number(q[0]); i++) {
        console.log(solve(q[i]))
    }
}
function solve(s) {
    const stack = {
        '1': 0,
        '2': 0,
        '3': 0
    };
    let min = 0, iter = 0;
    for(let i = 0; i < s.length; i++) {
        while(iter < s.length && (stack['1'] === 0 || stack['2'] === 0 || stack['3'] === 0)) {
            stack[s[iter++]]++;
        }
        let full = true;
        for(let i in stack) {
            full = full && stack[i]
        }
        if (full) {
            if (iter - i < min || min === 0) {
                min = iter - i;
            }
        }
        stack[s[i]]--;
    }
    return min;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const s = lines[i+1].split('').map(x => x - 1)
    let pos = [null, null, null]
    let min = null
    let count = 0
    for (let i =0; i<s.length; i++) {
      if (pos[s[i]] === null) {
        count++
      }
      pos[s[i]] = i
      if (count === 3) {
        let start = Math.min.apply(null, pos)
        let end = Math.max.apply(null, pos)
        const diff = end - start
        if (min === null) {
          min = diff
        } else {
          if (min > diff) {
            min = diff
          }
        }

      }
    }
    if (min === null) {
      console.log(0)
    } else {
      console.log(min+1)
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i <= Number(q[0]); i++) {
        console.log(solve(q[i]))
    }
}
function solve(s) {
    const stack = {
        '1': false,
        '2': false,
        '3': false
    };
    let count = 0, min = 0;
    function check(q) {
        count++;
        stack[q] = true;
        let full = true;
        for(let i in stack) {
            full = full && stack[i]
        }
        if (full) {
            for(let i in stack) {
                stack[i] = false;
            }
            if (count < min || min === 0) {
                min = count;
            }
            count = 0;
        }
    }
    for(let i of s) {
        check(i);
    }
    return min;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})


It has finally been decided to build a roof over the football field in School 179. Its construction will require placing $$$n$$$ consecutive vertical pillars. Furthermore, the headmaster wants the heights of all the pillars to form a permutation $$$p$$$ of integers from $$$0$$$ to $$$n - 1$$$, where $$$p_i$$$ is the height of the $$$i$$$-th pillar from the left $$$(1 \le i \le n)$$$.As the chief, you know that the cost of construction of consecutive pillars is equal to the maximum value of the bitwise XOR of heights of all pairs of adjacent pillars. In other words, the cost of construction is equal to $$$\max\limits_{1 \le i \le n - 1}{p_i \oplus p_{i + 1}}$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Find any sequence of pillar heights $$$p$$$ of length $$$n$$$ with the smallest construction cost.In this problem, a permutation is an array consisting of $$$n$$$ distinct integers from $$$0$$$ to $$$n - 1$$$ in arbitrary order. For example, $$$[2,3,1,0,4]$$$ is a permutation, but $$$[1,0,1]$$$ is not a permutation ($$$1$$$ appears twice in the array) and $$$[1,0,3]$$$ is also not a permutation ($$$n=3$$$, but $$$3$$$ is in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line for each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of pillars for the construction of the roof. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_n$$$ — the sequence of pillar heights with the smallest construction cost. If there are multiple answers, print any of them.

NoteFor $$$n = 2$$$ there are $$$2$$$ sequences of pillar heights:   $$$[0, 1]$$$ — cost of construction is $$$0 \oplus 1 = 1$$$.  $$$[1, 0]$$$ — cost of construction is $$$1 \oplus 0 = 1$$$. For $$$n = 3$$$ there are $$$6$$$ sequences of pillar heights:   $$$[0, 1, 2]$$$ — cost of construction is $$$\max(0 \oplus 1, 1 \oplus 2) = \max(1, 3) = 3$$$.  $$$[0, 2, 1]$$$ — cost of construction is $$$\max(0 \oplus 2, 2 \oplus 1) = \max(2, 3) = 3$$$.  $$$[1, 0, 2]$$$ — cost of construction is $$$\max(1 \oplus 0, 0 \oplus 2) = \max(1, 2) = 2$$$.  $$$[1, 2, 0]$$$ — cost of construction is $$$\max(1 \oplus 2, 2 \oplus 0) = \max(3, 2) = 3$$$.  $$$[2, 0, 1]$$$ — cost of construction is $$$\max(2 \oplus 0, 0 \oplus 1) = \max(2, 1) = 2$$$.  $$$[2, 1, 0]$$$ — cost of construction is $$$\max(2 \oplus 1, 1 \oplus 0) = \max(3, 1) = 3$$$.

const solve = n=>{
     if(n===2){
          console.log("0 1");
          return;
     }
     let t = 1<<(Math.floor(Math.log2(n-1)));
     let arr = [];
     for(let i=1;i<t;i++) arr.push(i);
     arr.push(0);
     arr.push(t);
     for(let i=t+1;i<n;i++) arr.push(i);
     console.log(arr.join(" "));
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       solve(n);
  }
}
main();

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 = lines[i];
        var b = 1;
        while(b * 2 < n){
            b *= 2;
        }
        var ans = '';
        for(j = b - 1; j >= 0; j--){
            ans += j + ' ';
        }
        for(j = b; j < n; j++){
            ans += j + ' ';
        }
        console.log(ans);
    }
});

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let x = 0;
		while (n-1 >= 1 << x) x++;
		x--;

		const ans = [];
		for (let i = n-1; i > 0; i--) {
			ans.push(i);
			if (i == 1 << x) ans.push(0);
		}

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

const main = () => {

	var t = readInt();
	while (t--) {
		var n = readInt();
		var largestPowOf2 = 1;
		var temp = n - 1;
		while ((temp >> 1) > 0) {
			temp >>= 1;
			largestPowOf2 <<= 1;
		}
		// Put 1,2,3,... 0, largestPower of 2, larger numbers
		var ans = [];
		for (var i = 1; i < largestPowOf2; i++)
			ans.push(i);
		ans.push(0);
		for (var i = largestPowOf2; i < n; i++)
			ans.push(i);
		oneLineArrayPrint(ans);
	}

	return;
}

const readInt = () => parseInt(readline());
const readString = () => readline();
const readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
const parseLong = (string) => { // javascript's largest long is < (1<<62)
	var n = string.length;
	var res = 0;
	for (var i = 0; i < n; i++) {
		res *= 10;
		res += parseInt(string[i]);
	}
	return res;
}
const readLong = () => parseLong(readLong());
const readLongArr = () => readline().split(" ").map(zzzz => parseLong(zzzz));
const oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
const multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
const multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));
const makeArr = (defaultVal, dimensionsArr) => {
	var n = dimensionsArr.length;
	if (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);
	else {
		var temp = [];
		for (var i = 0; i < dimensionsArr[0]; i++)
			temp.push(makeArr(defaultVal, dimensionsArr.slice(1)));
		return temp;
	}
}

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword. use "var" instead
// codeforces js cannot destructure arrays

const solve = n=>{
     let t = 1<<(Math.floor(Math.log2(n)));
     let arr = [];
     for(let i=1;i<t;i++) arr.push(i);
     arr.push(0);
     arr.push(t);
     for(let i=t+1;i<n;i++) arr.push(i);
     console.log(arr.join(" "));
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       solve(n);
  }
}
main();


Given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$, find the number of indices $$$1 \leq i \leq n - k$$$ such that the subarray $$$[a_i, \dots, a_{i+k}]$$$ with length $$$k+1$$$ (not with length $$$k$$$) has the following property:   If you multiply the first element by $$$2^0$$$, the second element by $$$2^1$$$, ..., and the ($$$k+1$$$)-st element by $$$2^k$$$, then this subarray is sorted in strictly increasing order.  More formally, count the number of indices $$$1 \leq i \leq n - k$$$ such that $$$$$$2^0 \cdot a_i < 2^1 \cdot a_{i+1} < 2^2 \cdot a_{i+2} < \dots < 2^k \cdot a_{i+k}.$$$$$$

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq k < n$$$) — the length of the array and the number of inequalities. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of indices satisfying the condition in the statement.

NoteIn the first test case, both subarrays satisfy the condition:   $$$i=1$$$: the subarray $$$[a_1,a_2,a_3] = [20,22,19]$$$, and $$$1 \cdot 20 < 2 \cdot 22 < 4 \cdot 19$$$.  $$$i=2$$$: the subarray $$$[a_2,a_3,a_4] = [22,19,84]$$$, and $$$1 \cdot 22 < 2 \cdot 19 < 4 \cdot 84$$$.  In the second test case, three subarrays satisfy the condition:   $$$i=1$$$: the subarray $$$[a_1,a_2] = [9,5]$$$, and $$$1 \cdot 9 < 2 \cdot 5$$$.  $$$i=2$$$: the subarray $$$[a_2,a_3] = [5,3]$$$, and $$$1 \cdot 5 < 2 \cdot 3$$$.  $$$i=3$$$: the subarray $$$[a_3,a_4] = [3,2]$$$, and $$$1 \cdot 3 < 2 \cdot 2$$$.  $$$i=4$$$: the subarray $$$[a_4,a_5] = [2,1]$$$, but $$$1 \cdot 2 = 2 \cdot 1$$$, so this subarray doesn't satisfy the condition.

'use strict';

function solve(n, m, a) {
  let res = 0;
  for (let i = 0, j = 0; i < n; i = ++j) {
    while (j + 1 < n && a[j] < a[j + 1] * 2) {
      j++;
    }
    res += Math.max(0, j - i + 1 - m);
  }
  return res;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, m, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

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

class INPUT {
	constructor() {
		this.input = '';
		this.curLine = 0;
	}

	append(str) {
		this.input += str;
	}

	prepare() {
		this.input = this.input.split('\n').map((str) => str.trim());
	}

	readline() {
		return this.input[this.curLine++];
	}

	readInts() {
		return this.readline()
			.split(' ')
			.map((x) => parseInt(x, 10));
	}
}

const input = new INPUT();

process.stdin.on('data', (str) => {
	input.append(str);
});

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

function solve() {
	let [n, k] = input.readInts();
	let a = input.readInts().map((x, idx) => Math.log2(x) + idx);
	let b = [...new Array(n - 1)].map((_, idx) =>
		a[idx + 1] <= a[idx] + 1e-9 ? 1 : 0
	);

	for (let i = 1; i < b.length; i++) {
		b[i] += b[i - 1];
	}

	let ans = 0;

	for (let i = 0; i < n - k; i++) {
		if (b[i + k - 1] - (i > 0 ? b[i - 1] : 0) === 0) {
			ans++;
		}
	}

	console.log(ans);
}

function main() {
	let [T] = input.readInts();

	while (T--) {
		solve();
	}
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  var [n,k] = readline().split(' ').map((x) => parseInt(x));
  var a = readline().split(' ').map((x) => parseInt(x));
  var ans = 0;
  var ok = []
  for(var i=1;i<n;i++) {
    ok[i] = ((a[i]/a[i-1]) > 0.5);
  }
  var j = 0;
  for(var i=1;i<n;i++) {
    if(!ok[i]) continue;
    j = max(i, j);
    while(j<n && ok[j]) j++;

    if((j-i)+1 > k) ans++;
  }

  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

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, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    const dp = []
    let ans = 0
    for (let i = 0; i < arr.length; i++) {
        if (i && arr[i - 1] < 2 * arr[i]) {
            dp[i] = dp[i - 1] + 1
        } else {
            dp[i] = 1
        }
        if (dp[i] >= k + 1) ans++
    }
            // console.log(dp)
    return ans
}

'use strict';

function solve(n, a) {
  const map = new Map();
  for (let [i, num] of a.entries()) {
    if (!map.has(num)) map.set(num, []);
    map.get(num).push(i);
  }
  let res = [1, a[0], 0, 0];
  for (let [num, list] of map) {
    const sum = [];
    let l = 0,
        r = 0;
    sum[0] = 1;
    for (let i = 1; i < list.length; i++) {
      var _list;
      const cur = sum[i - 1] - (list[i] - ((_list = list[i - 1]) !== null && _list !== void 0 ? _list : -1) - 1) + 1;
      if (cur > 0) {
        r = i;
      } else {
        l = i;
        r = i;
      }
      sum[i] = Math.max(0, cur);
      if (res[0] < sum[i]) {
        res = [sum[i], num, list[l], list[r]];
      }
    }
  }
  const [, x, y, z] = res;
  return `${x} ${y + 1} ${z + 1}`;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others. We define as bj the number of songs the group j is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers b1, b2, ..., bm will be as large as possible.Find this maximum possible value of the minimum among the bj (1 ≤ j ≤ m), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.

The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 2000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the performer of the i-th song.

In the first line print two integers: the maximum possible value of the minimum among the bj (1 ≤ j ≤ m), where bj is the number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Polycarp needs to make. In the second line print the changed playlist. If there are multiple answers, print any of them.

NoteIn the first sample, after Polycarp's changes the first band performs two songs (b1 = 2), and the second band also performs two songs (b2 = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any changes in the playlist. In the second sample, after Polycarp's changes the first band performs two songs (b1 = 2), the second band performs three songs (b2 = 3), and the third band also performs two songs (b3 = 2). Thus, the best minimum value is 2.

var arr = readline().split(' ');
var len = Number(arr[0]);
var max_f = Number(arr[1]);
var min = 0;
var op = 0;
var else_n = 0;
var min = Math.floor(len/max_f);

arr = readline().split(' ');

var obj = {};

var arr_h = [];
var indexs =[];

for (var i = 1;i <= max_f;i ++) {
	arr_h[i] = 0;
}

for (var i = 0 ;i < len;i ++) {
	arr[i] = Number(arr[i]);
}

for (var i = 0;i < len;i ++) {
	if (arr[i] <= max_f) {
		arr_h[arr[i]] ++;
		if (arr_h[arr[i]] > min) {
			indexs.push(i);
		}
	} else {
		else_n ++;
		indexs.push(i);
	}
}

var index = 0;

if (min == 0) {
	op = 0;
} else {
	for (var i = 0;i < arr_h.length;i ++) {
		if (arr_h[i] < min) {
			op += min - arr_h[i];
			var tmp = min - arr_h[i];
			while(tmp) {
				var _index = indexs[index];
				arr[_index] = i;
				index ++;
				tmp --;
			}
		}
	}
}

print(min + " " + op);
var _str = "";
for (var i = 0;i < arr.length;i ++) {
	_str += arr[i];
	if (i != arr.length - 1) {
		_str += ' ';
	}
}
print(_str);

var arr = readline().split(' ');
var len = Number(arr[0]);
var max_f = Number(arr[1]);
var min = 0;
var op = 0;
var else_n = 0;
var min = Math.floor(len/max_f);

arr = readline().split(' ');

var obj = {};

var arr_h = [];
var indexs =[];

for (var i = 0;i < max_f;i ++) {
	arr_h[i] = 0;
}

for (var i = 0 ;i < len;i ++) {
	arr[i] = Number(arr[i]);
}

for (var i = 0;i < len;i ++) {
	if (arr[i] <= max_f) {
		arr_h[arr[i]] ++;
		if (arr_h[arr[i]] > min) {
			indexs.push(arr_h[arr[i]]);
		}
	} else {
		else_n ++;
		indexs.push(arr[i]);
	}
}

var index = 0;

if (min == 0) {
	op = 0;
} else {
	for (var i = 0;i < arr_h.length;i ++) {
		if (arr_h[i] < min) {
			op += min - arr_h[i];
			var tmp = min - arr_h[i];
			while(tmp) {
				var _index = indexs[index];
				arr[_index] = i;
				index ++;
				tmp --;
			}
		}
	}
}

print(min + " " + op);
print(arr);