There are $$$n$$$ people participating in some contest, they start participating in $$$x$$$ minutes intervals. That means the first participant starts at time $$$0$$$, the second participant starts at time $$$x$$$, the third — at time $$$2 \cdot x$$$, and so on.Duration of contest is $$$t$$$ minutes for each participant, so the first participant finishes the contest at time $$$t$$$, the second — at time $$$t + x$$$, and so on. When a participant finishes the contest, their dissatisfaction equals to the number of participants that started the contest (or starting it now), but haven't yet finished it.Determine the sum of dissatisfaction of all participants.

The first line contains a single integer $$$k$$$ ($$$1 \le k \le 1000$$$) — the number of test cases. Each of the next $$$k$$$ lines contains three integers $$$n$$$, $$$x$$$, $$$t$$$ ($$$1 \le n, x, t \le 2 \cdot 10^9$$$) — the number of participants, the start interval and the contest duration.

Print $$$k$$$ lines, in the $$$i$$$-th line print the total dissatisfaction of participants in the $$$i$$$-th test case.

NoteIn the first example the first participant starts at $$$0$$$ and finishes at time $$$5$$$. By that time the second and the third participants start, so the dissatisfaction of the first participant is $$$2$$$. The second participant starts at time $$$2$$$ and finishes at time $$$7$$$. By that time the third the fourth participants start, so the dissatisfaction of the second participant is $$$2$$$. The third participant starts at $$$4$$$ and finishes at $$$9$$$. By that time the fourth participant starts, so the dissatisfaction of the third participant is $$$1$$$.The fourth participant starts at $$$6$$$ and finishes at $$$11$$$. By time $$$11$$$ everyone finishes the contest, so the dissatisfaction of the fourth participant is $$$0$$$.In the second example the first participant starts at $$$0$$$ and finishes at time $$$2$$$. By that time the second participants starts, and the third starts at exactly time $$$2$$$. So the dissatisfaction of the first participant is $$$2$$$. The second participant starts at time $$$1$$$ and finishes at time $$$3$$$. At that time the third participant is solving the contest.

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

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, d, tot] = readline()
      .trim()
      .split(" ")
      .map((cur) => BigInt(cur));
    let l = tot / d;
    if (l >= n) {
      n--;
      console.log((n * (n + 1n)) / 2n + "");
      continue;
    }
    n--;
    let i = (n - (l - 1n)) * l;
    let j = n - (n - (l - 1n));
    i += (j * (j + 1n)) / 2n;
    console.log(i + "");
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var args = lines[l++].split(' ').map(Number)
        console.log(solve(args));
    }
});

function solve([n, x, t]) {
    const k = Math.min(n, Math.floor(t / x))
    const rest = BigInt(k - 1 + 1) * BigInt(k - 1) / 2n
    const br = BigInt(n - k) * BigInt(k) + rest
    return br.toString()
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        let n,x,t;
        [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));
        if (t<x) {
           console.log(0);
           continue;
        }
        let bad = Math.floor(t/x);
        bad = BigInt(bad);
        n = BigInt(n);
        if (bad > n) {
            console.log((n * (n- BigInt(1)) / BigInt(2)).toString());
        }
        else {
            console.log((n * bad - bad * (bad + BigInt(1)) / BigInt(2)).toString());
        }

    }
}

solve();

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 06/21/21 morning
const solve = (n, x, t) => {
    let each = t / x;
    let len = mill(n, each);
    let res = (n - len) * each + (len - 1n) * len / 2n;
    pr(res.toString());
};

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

main()

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const k = input.number();
    const ans = Array(k);
    for (let i = 0; i < k; i++) {
        const [n, x, t] = input.bigints(3);
        const c = t / x;
        const m = bigIntMin(c, n);
        ans[i] = n * c - (c * (c + 1n)) / 2n + ((c - m) * (c - m + 1n)) / 2n;
    }
    console.log(ans.join('\n'));
}
main();
//# sourceMappingURL=aoj.js.map

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function div(a, b) {
   return Math.floor(a / b);
}

function solve() {
   var nxt = readArray(BigInt);
   var n = nxt[0];
   var x = nxt[1];
   var t = nxt[2];
   var maxAngry = t / x;
   if (n <= maxAngry + 1n) {
      write(n * (n - 1n) / 2n);
      return;
   }
   write((maxAngry * (maxAngry - 1n) / 2n) + (maxAngry * (n - maxAngry)));
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

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

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, d, tot] = readline()
      .trim()
      .split(" ")
      .map((cur) => BigInt(cur));
    let l = tot / d;
    if (l >= n) {
      l--;
      console.log((l * (l + 1n)) / 2n + "");
      continue;
    }
    n--;
    let i = (n - (l - 1n)) * l;
    let j = n - (n - (l - 1n));
    i += (j * (j + 1n)) / 2n;
    console.log(i + "");
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var args = lines[l++].split(' ').map(Number)
        console.log(solve(args));
    }
});

function solve([n, x, t]) {
    const k = Math.floor(t / x)
    const rest = BigInt(k - 1 + 1) * BigInt(k - 1) / 2n
    const br = BigInt(n - k) * BigInt(k) + rest
    return br.toString()
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var args = lines[l++].split(' ').map(Number)
        console.log(solve(args));
    }
});

function solve([n, x, t]) {
    const k = Math.floor(t / x)
    const rest = (k - 1 + 1) * (k - 1) / 2
    return (n - k) * k + rest
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        let n,x,t;
        [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));
        if (t<x) {
           console.log(0);
           continue;
        }
        let bad = Math.floor(t/x);
        bad = BigInt(bad);
        n = BigInt(n);
        console.log((n * bad - bad*(bad+BigInt(1))/BigInt(2)).toString());

    }
}

solve();

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        let n,x,t;
        [n,x,t] = (await getLine()).split(' ').map(num => parseInt(num));
        if (t<x) {
           console.log(0);
           continue;
        }
        let bad = Math.floor(t/x);
        console.log(n * bad - bad*(bad+1)/2);

    }
}

solve();

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 06/21/21 morning
const solve = (n, x, t) => {
    let each = t / x >> 0;
    let len = mi(n, each);
    pr((n - len) * each + (len - 1) * len / 2);
};

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

main()

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const k = input.number();
    const ans = Array(k);
    for (let i = 0; i < k; i++) {
        const [n, x, t] = input.bigints(3);
        const c = t / x;
        ans[i] = n * c - (c * (c + 1n)) / 2n;
    }
    console.log(ans.join('\n'));
}
main();
//# sourceMappingURL=aoj.js.map


Vivek has encountered a problem. He has a maze that can be represented as an $$$n \times m$$$ grid. Each of the grid cells may represent the following:  Empty — '.'  Wall — '#'  Good person  — 'G'  Bad person — 'B' The only escape from the maze is at cell $$$(n, m)$$$.A person can move to a cell only if it shares a side with their current cell and does not contain a wall. Vivek wants to block some of the empty cells by replacing them with walls in such a way, that all the good people are able to escape, while none of the bad people are able to. A cell that initially contains 'G' or 'B' cannot be blocked and can be travelled through.Help him determine if there exists a way to replace some (zero or more) empty cells with walls to satisfy the above conditions.It is guaranteed that the cell $$$(n,m)$$$ is empty. Vivek can also block this cell.

The first line contains one integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$m$$$ $$$(1 \le n, m \le 50)$$$ — the number of rows and columns in the maze. Each of the next $$$n$$$ lines contain $$$m$$$ characters. They describe the layout of the maze. If a character on a line equals '.', the corresponding cell is empty. If it equals '#', the cell has a wall. 'G' corresponds to a good person and 'B' corresponds to a bad person.

For each test case, print "Yes" if there exists a way to replace some empty cells with walls to satisfy the given conditions. Otherwise print "No" You may print every letter in any case (upper or lower).

NoteFor the first and second test cases, all conditions are already satisfied.For the third test case, there is only one empty cell $$$(2,2)$$$, and if it is replaced with a wall then the good person at $$$(1,2)$$$ will not be able to escape.For the fourth test case, the good person at $$$(1,1)$$$ cannot escape.For the fifth test case, Vivek can block the cells $$$(2,3)$$$ and $$$(2,2)$$$.For the last test case, Vivek can block the destination cell $$$(2, 2)$$$.

// const bg = require('big-integer')
process.stdin.resume()
process.stdin.setEncoding('utf-8')
const MOD1 = 1000000007

function alpha(c = 'A') {
  return [...{
    _b: c === 'A' ? 65 : 97,
    _i: -1,
    [Symbol.iterator]() {
      return this
    },
    next() {
      this._i++
      if (this._i === 26) return {done: true}
      else return {done: false, value: String.fromCharCode(this._i + this._b)}
    }
  }]
}

class rc {
  static construct() {
    this.input = ''
    this.ptr = 0
  }
  static readString() {
    return this.input[this.ptr++]
  }

  static readStrings() {
    return this.input[this.ptr++].split(' ')
  }

  static readInt() {
    return +this.readString()
  }

  static readInts() {
    return this.readStrings().map(a => +a)
  }

  static readBigInteger() {
    return bg(this.readString())
  }

  static readBigIntegers() {
    return this.readStrings().map(a => bg(a))
  }
}

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

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

Array.fill = function(n, m, no = 0) {
  const a = new Array(n)
  for(let i = 0; i < n; i++) a[i] = new Array(m).fill(no)
  return a
}

rc.construct()
// bc.construct()
process.stdin.on('data', (i) => {
  rc.input += i
})

process.stdin.on('end', () => {
  rc.input = rc.input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  let hasTestCases = true
  if(hasTestCases) {
    let t = rc.readInt()
    while(t--) main()
  }
  else main()
})

function main() {
  const [n, m] = rc.readInts()
  const a = new Array(n)
  for (let i = 0; i < n; i++) a[i] = rc.readString().split('')

  let canPass = true

  // wr(a)

  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      if(a[i][j] === 'B') {
        canPass = checkBorder(i - 1, j) && checkBorder(i, j - 1) && checkBorder(i + 1, j) && checkBorder(i, j + 1)
        if(!canPass) {
          wr('No')
          return
        }
      }
    }
  }

  const r = Array.fill(n, m)

  let queue = []
  if(a[n - 1][m - 1] !== '#') queue.push([n - 1, m - 1])

  while(queue.length) {
    let newQueue = []
    queue.forEach(([i, j]) => {
      r[i][j] = 1
      markR(i - 1, j)
      markR(i + 1, j)
      markR(i, j - 1)
      markR(i, j + 1)
      function  markR(i, j) {
        if(i >= 0 && i < n && j >= 0 && j < m) {
          if((a[i][j] === 'G' || a[i][j] === '.') && !r[i][j]) {
            r[i][j] = 1
            newQueue.push([i, j])
          }
        }
      }
    })
    queue = newQueue
  }

  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      if(a[i][j] === 'G' && !r[i][j]) {
        wr('No')
        return
      }
    }
  }

  wr('Yes')

  function checkBorder(i, j) {
    if(i >= 0 && i < n && j >= 0 && j < m) {
      if(a[i][j] === 'G') {
        return false
      }
      if(a[i][j] !== 'B') a[i][j] = '#'
    }
    return true
  }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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(){
	//1365D
	var t = nextInt();
	var output = new Array(t);
	var dy = [-1,0,1,0];
	var dx = [0,-1,0,1];
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		var list = new Array(N);
		var isG = false;
		var isB = false;
		var bList = [];
		var gList = [];
		for(var j = 0; j < N; j++){
			list[j] = nextCharArray();
			for(var k = 0; k < M; k++){
				if(list[j][k] == "G"){
					isG = true;
					gList.push([j,k]);
				}
				if(list[j][k] == "B"){
					isB = true;
					bList.push([j,k]);
				}
			}
		}
		if(isG){
			var gCount = 0;
			//両方いるときがヤバイ
			//とりあえずBの4方を防いでしまう
			for(var j = 0; j < bList.length; j++){
				for(var k = 0; k < dy.length; k++){
					var tonariY = bList[j][0] + dy[k];
					var tonariX = bList[j][1] + dx[k];
					if(tonariY < N && tonariY >= 0 && tonariX < M && tonariX >= 0){
						if(list[tonariY][tonariX] != "G" && list[tonariY][tonariX] != "B"){
							list[tonariY][tonariX] = "#";
						}
					}
				}
			}
			function bfs(startY, startX){
				var access = new Array(N);
				var sIndex = 0;
				var eIndex = 1;
				for(var l = 0; l < N; l++){
					access[l] = new Array(M).fill(false);
				}
				var queue = new Array(4000);
				queue[0] = [startY, startX];
				access[startY][startX] = true;
				while(sIndex != eIndex){
					var tmp = queue[sIndex];
					sIndex++;
					var y = tmp[0];
					var x = tmp[1];
					if(list[y][x] == "B"){
						isOK = false;
						return;
					}else if(list[y][x] == "G"){
						gCount++;
					}
					for(var l = 0; l < dy.length; l++){
						var nextY = y + dy[l];
						var nextX = x + dx[l];
						if(nextY < N && nextY >= 0 && nextX < M && nextX >= 0){
							if(!access[nextY][nextX] && list[nextY][nextX] != "#"){
								access[nextY][nextX] = true;
								queue[eIndex] = [nextY, nextX];
								eIndex++;
							}
						}
					}
				}
				return;
			}
			var isOK = true;
			bfs(N - 1, M - 1);
			if(!isOK || gCount != gList.length){
				output[i] = "No";
				continue;
			}
			output[i] = "Yes";
		}else{
			output[i] = "Yes";
		}
	}
	myout(myconv(output,9));
}

'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++];
}
/**
6
1 1
.
1 2
G.
2 2
#B
G.
2 3
G.#
B#.
3 3
#B.
#..
GG.
2 2
#B
B.
**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

Array.fill = function(n, m, no = 0) {
  const a = new Array(n)
  for(let i = 0; i < n; i++) a[i] = new Array(m).fill(no)
  return a
}

function main() {
    let range = parseInt(readline());

    for(let r = 0;r<range;r++) {
        solve();
    }
}

function solve() {
    let [n, m] = readline().split(" ").map(Number);

        const a = [];
        for(let i=0;i<n;i++) {
            a.push(readline().split(""));
        }

        let canPass = true;

        for(let i=0;i<n;i++) {
            for(let j=0;j<m;j++) {
                if(a[i][j] === 'B') {
                    canPass = checkBorder(i, j-1) && checkBorder(i - 1, j) && checkBorder(i+1, j) && checkBorder(i, j+1);
                    if(canPass === false) {
                        console.log('No');
                        return;
                    }
                }
            }
        }

        let quene = [];
        if(a[n-1][m-1] !== '#') {
            quene.push([n-1, m-1]);
        }

        const r = Array.fill(n, m)

        while(quene.length) {
            let newQuene = [];
            quene.forEach(([i, j]) => {
                r[i][j] = 1;
                bfs(i, j - 1);
                bfs(i - 1, j);
                bfs(i, j + 1);
                bfs(i + 1, j);

                function bfs(i, j) {
                    if(i >= 0 && j >= 0 && i < n && j < m) {
                        if((a[i][j] === 'G' || a[i][j] === '.') && !r[i][j]) {
                            r[i][j] = 1;
                            newQuene.push([i, j]);
                        }
                    }
                }
            });
            quene = newQuene;
        }

        for(let i=0;i<n;i++) {
            for(let j=0;j<m;j++) {
                if(a[i][j] === 'G' && !r[i][j]) {
                    console.log('No');
                    return;
                }
            }
        }

        console.log('Yes');

        function checkBorder(i, j) {
            if(i >= 0 && i < n && j >= 0 && j < m) {
              if(a[i][j] === 'G') {
                return false
              }
              if(a[i][j] !== 'B') a[i][j] = '#'
            }
            return true
        }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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(){
	var t = nextInt();
	var output = new Array(t);
	var dy = [-1,0,1,0];
	var dx = [0,-1,0,1];
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		var list = new Array(N);
		var isG = false;
		var isB = false;
		for(var j = 0; j < N; j++){
			list[j] = nextCharArray();
			if(list[j].indexOf("G") != -1){
				isG = true;
			}
			if(list[j].indexOf("B") != -1){
				isB = true;
			}
		}
		if(isG && isB){
			//両方いるときがヤバイ
			//とりあえずBの4方を防いでしまう
			for(var j = 0; j < N; j++){
				for(var k = 0; k < M; k++){
					if(list[j][k] == "B"){
						for(var l = 0; l < dy.length; l++){
							var tonariY = j + dy[l];
							var tonariX = k + dx[l];
							if(tonariY < N && tonariY >= 0 && tonariX < M && tonariX >= 0){
								if(list[tonariY][tonariX] != "G" && list[tonariY][tonariX] != "B"){
									list[tonariY][tonariX] = "#";
								}
							}
						}
					}
				}
			}
			function bfs(startY, startX, isGood){
				var access = new Array(N);
				for(var l = 0; l < N; l++){
					access[l] = new Array(M).fill(false);
				}
				var queue = [[startY, startX]];
				access[startY][startX] = true;
				while(queue.length > 0){
					var tmp = queue.shift();
					var y = tmp[0];
					var x = tmp[1];
					if(y == N - 1 && x == M - 1){
						return isGood;
					}
					for(var l = 0; l < dy.length; l++){
						var nextY = y + dy[l];
						var nextX = x + dx[l];
						if(nextY < N && nextY >= 0 && nextX < M && nextX >= 0){
							if(!access[nextY][nextX] && list[nextY][nextX] != "#"){
								access[nextY][nextX] = true;
								queue.push([nextY, nextX]);
							}
						}
					}
				}
				return !isGood;
			}
			var isOK = true;
			for(var j = 0; j < N; j++){
				for(var k = 0; k < M; k++){
					if(list[j][k] == "B"){
						var res = bfs(j,k,false);
						if(!res){
							isOK = false;
						}
					}
				}
			}
			if(!isOK){
				output[i] = "No";
				continue;
			}
			for(var j = 0; j < N; j++){
				for(var k = 0; k < M; k++){
					if(list[j][k] == "G"){
						var res = bfs(j,k,true);
						if(!res){
							isOK = false;
						}
					}
				}
			}
			if(!isOK){
				output[i] = "No";
				continue;
			}
			output[i] = "Yes";
		}else{
			output[i] = "Yes";
		}
	}
	myout(myconv(output,9));
}


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero):   choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$).

For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal:  Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$.  Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal:   Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$.  Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$.  Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$.  Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$.

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var caseArray = readline().split(" ");
    var flag = true;
    for (var j = 1; j < caseLength; j++)
    {
        var value = parseInt(caseArray[j]) - parseInt(caseArray[j-1]);
        if (value % parseInt(caseArray[0]) !== 0)
        {
            flag = false;
            break;
        }
    }
    if (flag) print("YES"); else print("NO");
}

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var n = parseInt(readline());
        var arr = readline().split(' ').map(x=>parseInt(x));
        var ans = 'yes';
        for (var i=1; i<n; i++) {
            if (arr[i] % arr[0] != 0) {
                ans = 'no';
                break;
            }

        }
        print(ans);
    }

const main = () => {

	var t = readInt();
	var allans = [];
	for (var zz = 0; zz < t; zz++) {
		var n = readInt();
		var a = readIntArr();
		var z = a[0];
		var ans = 'YES';
		for (var i = 1; i < n; i++)
			if (a[i] % z !== 0)
				ans = 'NO';
		allans.push(ans);
	}
	multiLineArrayPrint(allans);

	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

T = readline()

while(T--){
      n = readline()
      a = readline().split(' ').map(el => +el)

      ans = 'YES'
      for(i = 1; i< n; i++){
            if(a[i]%a[0] != 0){
                  ans = 'NO'
                  break
            }
      }

      print(ans)
}

        process.stdin.resume();
        process.stdin.setEncoding('utf-8');
        let inputString = '', 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++];
        }

        function main() {
            const t = parseInt(readLine(), 10);
            for(let i = 0; i < t; i++){
                const n = readLine();
                const arr = readLine().split(' ').map(p => +p);
                let result = myFunc(arr, n);
                console.log(result);
            }
        }

        function myFunc(arr, n){
            for(let i = 1; i < n; i++){
                if(arr[i] % arr[0] != 0) return 'NO';
            }
            return 'YES';
        }

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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const t = readline();

  for (let i = 0; i < t; i++) {
    const n = parseInt(readline(), 10);

    const a = readline()
      .split(' ')
      .map((num) => +num);

    // console.log(`=----------------testcase ${i + 1}----------------=`);
    // console.log('q', q);
    // console.log('a', a);

    const output = f(n, a);

    console.log(output);
  }
}

function f(n, a) {
  return a.slice(1).some(x => x % a[0]) ? 'NO' : 'YES'
}

'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 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++) {
        readline();
        let arr = readline().split(' ').map(Number);
        let yes = true;
        for (let i = 1; i < arr.length; i++) {
            if (arr[i] % arr[0] !== 0) yes= false;
        }

        output(yes ? 'YES' : 'NO');
    }
}

'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 main(){
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        var n = parseInt(readline());
        var a = readline().split(" ").map(x=> parseInt(x));
        let res = true;
        for (let i = 0; i < n;++i) {
            if (a[i] % a[0] != 0) {
                res = false;
            }
        }
        if (res) {
            console.log('YES');
        } else {
            console.log('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 list = nextIntArray(N);
		for(var i = N - 1; i > 0; i--){
			list[i] %= list[i - 1];
		}
		var ok = true;
		for(var i = 1; i < N; i++){
			if(list[i] % list[0] != 0){
				ok = false;
			}
		}
		myout((ok) ? "YES" : "NO");
	}
}

'use strict';

function solve(n, a) {
  for (let i = 1; i < n; i++) {
    if (a[i] % a[0] !== 0) return 'NO';
  }
  return 'YES';
}

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);
});

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let div = arr[0],
      ans = true;
    for (let i = 1; i < n; i++) {
      if (arr[i] % div !== 0) {
        ans = false;
        break;
      }
    }
    console.log(`${ans === true ? "YES" : "NO"}`);
  }
};
solve();

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var n = parseInt(readline());
        var arr = readline().split(' ').map(x=>parseInt(x));
        var ans = 'yes';
        for (var i=1; i<n; i++) {
            if (arr[i-1] == 1) {
                break;
            }
            if (arr[i] % arr[i-1] != 0) {
                ans = 'no';
                break;
            }

        }
        print(ans);
    }

    process.stdin.resume();
    process.stdin.setEncoding('utf-8');
    let inputString = '', 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++];
    }

    function main() {
        const t = parseInt(readLine(), 10);
        for(let i = 0; i < t; i++){
            const n = readLine();
            const arr = readLine().split(' ').map(p => +p);
            let result = myFunc(arr, n);
            console.log(result);
        }
    }

    function myFunc(arr, n){
        for(let i = 1; i < n; i++){
            if(arr[i] < arr[i-1] || arr[i] % arr[0] != 0) return 'NO';
        }
        return 'YES';
    }

    process.stdin.resume();
    process.stdin.setEncoding('utf-8');
    let inputString = '', 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++];
    }

    function main() {
        const t = parseInt(readLine(), 10);
        for(let i = 0; i < t; i++){
            const n = readLine();
            const arr = readLine().split(' ').map(p => +p);
            let result = myFunc(arr, n);
            console.log(result);
        }
    }

    function myFunc(arr, n){
        for(let i = 1; i < n; i++){
            if(arr[i] < arr[i-1]) return 'NO';
        }
        return 'YES';
        return 'YES';
    }

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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const t = readline();

  for (let i = 0; i < t; i++) {
    const n = parseInt(readline(), 10);

    const a = readline().split(' ').map(num => +num);

    // console.log(`=----------------testcase ${i + 1}----------------=`);
    // console.log('q', q);
    // console.log('a', a);

    const output = f(n, a);

    console.log(output);
  }
}

function f(n, a) {

  for (let i = 1; i < n; i++) {
    if(a[i] < a[i-1]) return 'NO'
  }

  return 'YES';
}


Martians are actively engaged in interplanetary trade. Olymp City, the Martian city known for its spaceport, has become a place where goods from all the corners of our Galaxy come. To deliver even more freight from faraway planets, Martians need fast spaceships.A group of scientists conducts experiments to build a fast engine for the new spaceship. In the current experiment, there are $$$n$$$ elementary particles, the $$$i$$$-th of them has type $$$a_i$$$.Denote a subsegment of the particle sequence ($$$a_1, a_2, \dots, a_n$$$) as a sequence ($$$a_l, a_{l+1}, \dots, a_r$$$) for some left bound $$$l$$$ and right bound $$$r$$$ ($$$1 \le l \le r \le n$$$). For instance, the sequence $$$(1\ 4\ 2\ 8\ 5\ 7)$$$ for $$$l=2$$$ and $$$r=4$$$ has the sequence $$$(4\ 2\ 8)$$$ as a subsegment. Two subsegments are considered different if at least one bound of those subsegments differs.Note that the subsegments can be equal as sequences but still considered different. For example, consider the sequence $$$(1\ 1\ 1\ 1\ 1)$$$ and two of its subsegments: one with $$$l=1$$$ and $$$r=3$$$ and another with $$$l=2$$$ and $$$r=4$$$. Both subsegments are equal to $$$(1\ 1\ 1)$$$, but still considered different, as their left and right bounds differ.The scientists want to conduct a reaction to get two different subsegments of the same length. Denote this length $$$k$$$. The resulting pair of subsegments must be harmonious, i. e. for some $$$i$$$ ($$$1 \le i \le k$$$) it must be true that the types of particles on the $$$i$$$-th position are the same for these two subsegments. For example, the pair $$$(1\ 7\ 3)$$$ and $$$(4\ 7\ 8)$$$ is harmonious, as both subsegments have $$$7$$$ on the second position. The pair $$$(1\ 2\ 3)$$$ and $$$(3\ 1\ 2)$$$ is not harmonious.The longer are harmonious subsegments, the more chances for the scientists to design a fast engine. So, they asked you to calculate the maximal possible length of harmonious pair made of different subsegments.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following are descriptions of the test cases. The first line contains an integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the amount of elementary particles in the sequence. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 150\,000$$$) — types of elementary particles. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^5$$$.

For each test, print a single integer, maximal possible length of harmonious pair made of different subsegments. If such pair does not exist, print $$$-1$$$ instead.

NoteThe first test case is shown on the picture below:  As you can see from it, you may choose the subsegments $$$(2\ 1\ 3\ 4)$$$ and $$$(3\ 1\ 5\ 2)$$$, which are a harmonious pair. Their length is equal to $$$4$$$, so the answer is $$$4$$$.In the second test case, you need to take two subsegments: one with $$$l=1$$$ and $$$r=5$$$, and one with $$$l=2$$$ and $$$r=6$$$. It's not hard to observe that these segments are a harmonious pair and considered different even though they are both equal to $$$(1\ 1\ 1\ 1\ 1)$$$.In the third test case, you cannot make a harmonious pair, so the answer is $$$-1$$$.

const solve = arr=>{
   let obj = {};
     let max = 0;
     for(let i=0;i<arr.length;i++){
          if(obj[arr[i]]!==undefined){
               let t = arr.length - (i - obj[arr[i]]);
               max = Math.max(max,t);
               obj[arr[i]] = i;
          }
          else obj[arr[i]] = i;
     }
     if(max===0) console.log(-1);
     else console.log(max);
}
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());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

let dataitr;
let stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", (input) => {
  stdin_input += input;
});
process.stdin.on("end", () => {
  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));
// Make a Snippet for the code above this and then write your logic in main();

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

    let ans = -1;
    const types = {};
    let minBetween = n + 1;
    for (let i = 0; i < n; i++) {
      if (types[`${a[i]}`] === undefined) {
        types[`${a[i]}`] = i;
        continue;
      }

      const last = types[`${a[i]}`];
      const between = i - last;

      if (between === 1) {
        ans = n - 1;
        break;
      }

      types[`${a[i]}`] = i;

      if (minBetween > between) {
        minBetween = between;
      }
    }

    if (ans === -1) {
      ans = n - minBetween;
    }

    console.log(ans);
  }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;

	let t = inputReader.readNumber();

	function solve() {
	  let n = inputReader.readNumber();
	  let v = inputReader.readNumberArray();
	  let m = new Map();
	  let ans = -1;
	  for(let i = 0; i < n; i++) {
	    if(m.has(v[i])) {
	      ans = Math.max(ans, m.get(v[i]) + n - i);
	    }
	    m.set(v[i], i);
	  }
	  console.log(ans);
	}

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

	//cp-convert -s CP.js -d CP-CF.js

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

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));

const INF = 1e9;

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

		const mp = new Map();
		let mnd = INF;
		for (let i = 0; i < n; i++) {
			if (mp.has(a[i])) {
				mnd = Math.min(mnd, i - mp.get(a[i]));
			}
			mp.set(a[i], i);
		}

		console.log(mnd < INF ? n - mnd : -1);
	}
}

const readline = require('readline')

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

function solve(n, arr) {
    // const min = {}
    // const max = {}
    const p = {}
    arr.forEach((x, i) => {
        p[x] = p[x] || []
        p[x].push(i)
        // min[x] = (x in min) ? Math.min(min[x], i) : i
        // max[x] = (x in max) ? Math.max(max[x], i) : i
    })
    // console.log(min, max)
    let ans = -1
    for (let x in p) {
        // const a = min[x]
        // const b = max[x]
        if (p[x].length < 2) continue
        // if (a !== b) {
        //     const prev = Math.min(a, b)
        //     const after = Math.min(n - 1 - a, n - 1 - b)
        //     ans = Math.max(ans, prev + 1 + after)
        // }
        for (let i = 1; i < p[x].length; i++) {
            const a = p[x][i - 1]
            const b = p[x][i]
            ans = Math.max(ans, a + 1 + (n - 1 - b))
        }
    }
    return ans
}

const solve = arr=>{
   let obj = {};
     let max = 0;
     for(let i=0;i<arr.length;i++){
          if(obj[arr[i]]!==undefined){
               let t = arr.length - (i - obj[arr[i]]);
               if(t*2>=arr.length){
                    max = Math.max(max,t);
               }
               obj[arr[i]] = i;
          }
          else obj[arr[i]] = i;
     }
     if(max===0) console.log(-1);
     else console.log(max);
}
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());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
   let obj = {};
     let max = 0;
     for(let i=0;i<arr.length;i++){
          if(obj[arr[i]]!==undefined){
               let t = arr.length - (i - obj[arr[i]]);
               if(t*2>=arr.length){
                    max = Math.max(max,t);
                    break;
               }
          }
          else obj[arr[i]] = i;
     }
     if(max===0) console.log(-1);
     else console.log(max);
}
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());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
 let obj = {};
     for(let i=0;i<arr.length;i++){
          if(obj[arr[i]]) obj[arr[i]].push(i);
          else obj[arr[i]] = [i];
     }
     arr.sort((a,b)=>a-b);
     let max = 0;
     for(let i=0;i<arr.length-1;i++){
          if(arr[i]===arr[i+1]){
               let t = obj[arr[i]];
               for(let j=t.length-1;j>0;j--){
                    let k = arr.length-(t[j]-t[j-1]);
                    if(k*2>=arr.length){
                         max = Math.max(max,k);
                         break;
                    }
               }
               if(t.length===arr.length) break;
          }
     }
     if(max===0) console.log(-1);
     else console.log(max);
}
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());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();


Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases.  The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).

For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.

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

'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();
});

const readline = () => inputString[currentLine++];
const readline_arr = () => readline().split('');
const readline_num_arr = () => readline().split(' ').map((n) => parseInt(n, 10));
const print = (...txt) => process.stdout.write(`${txt}\n`)
/* ================== */

function main() {
  let t = parseInt(readline(), 10);
  while (t--) {
    solve();
  }
}

const checkPermute = (p) => {
  for (let i = 2; i < p.length; i++) {
    if (p[i - 2] + p[i - 1] === p[i]) {
      return false;
    }
  }

  return true;
}

function solve() {
  const n = parseInt(readline());
  for (let i = 1; i <= n; i++) {
    const res = [];
    res.push(i)

    for (let j = n; j >= 1; j--) {
      if (j !== i) res.push(j);
    }

    print(res.join(' '));
  }
}

'use strict';

function solve(n) {
  if (n === 3) return `1 3 2\n2 3 1\n3 1 2`;
  const s = Array.from({
    length: n
  }, (_, i) => n - i);
  const res = Array.from({
    length: n
  }, () => new Array(n));
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < n; j++) {
      res[i][j] = s[(j + i) % n];
    }
  }
  return res.map(arr => arr.join(' ')).join('\n');
}

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());
      res[i] = solve(n);
    }
    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');

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] = readline().split(' ').map(Number);

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

        for (let i = 1; i <= n; i++) {
            let res = [i];
            let m = perm.filter( x => x !== i)
            m.sort((a, b) => b - a);
            output([...res, ...m].join(' '));
        }
    }
}

const readline = require('readline')

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

function solve(n) {
    const ans = []
    for (let i = 0; i < n; i++) {
        const now = [i + 1]
        for (let j = n; j >= 1; j--) {
            if (j === i + 1) continue
            now.push(j)
        }
        ans[i] = now.join(' ')
    }
    return ans.join('\n')
}

function solve(input) {
    const len = parseInt(input)
    const out = 3;
    const list = Array.from({length: len}, (_, i) => i + 1);
    // 2 3 4 ... n 1
    console.log([...Array.from({length: len - 1}, (_, i) => i + 2), 1].join(' '))
    // 3 4 5 ... n 1 2
    console.log([...Array.from({length: len - 2}, (_, i) => i + 3), 1, 2].join(' '))
    // mundur
    console.log([...Array.from({length: len}, (_, i) => len - i)].join(' '))
    if (len > 3) {
      let baseList = Array.from({length: len}, (_, i) => len - i);
      for (let i = 3; i < len; i++) {
        const awal = baseList[0]
        baseList = [...baseList, awal].slice(1, len + 1)
        console.log(baseList.join(' '))
      }
    }
}

// =========== DEFAULT FORMAT ==============
const readline = require('readline').createInterface({ input: process.stdin });

let i = 1;
let t = 0;
readline.on('line', line => {
    if (i == 1) {
        // number of test case
        t = parseInt(line)
        i++;
    } else {
        solve(line)
        if (i <= t) i++
        else readline.close()
    }
});

// =========== DEFAULT FORMAT END ==============

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline();

  for (var j = 1; j <= n; ++j) {
    write(j);
    for (var k = n; k > 0; --k) {
      if (j != k) {
        write(' ',k);
      }
    }
    print();
  }
}

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var r = lines[j].split(' ').map(Number);
        var a = r[0];
        var b = r[1];
        var k = r[2];
        var d = 0;
        var answer = 0;
        if(k % 2 == 1){
            d = Math.floor(k / 2);
        }else{
            d = k / 2;
        }
        answer = (d * a) - ((k - d) * b);
        console.log(answer);
    }
});

'use strict';

function solve(n) {
  const s = Array.from({
    length: n
  }, (_, i) => n - i);
  const res = Array.from({
    length: n
  }, () => new Array(n));
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < n; j++) {
      res[i][j] = s[(j + i) % n];
    }
  }
  return res.map(arr => arr.join(' ')).join('\n');
}

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());
      res[i] = solve(n);
    }
    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);
});


Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number.

First line contains two integers R (1 ≤ R ≤ 500) and C (1 ≤ C ≤ 500), denoting the number of rows and the numbers of columns respectively. Each of the following R lines is a string consisting of exactly C characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.

If it is impossible to protect all sheep, output a single line with the word "No". Otherwise, output a line with the word "Yes". Then print R lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf. If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.

NoteIn the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.In the second example, there are no empty spots to put dogs that would guard the lone sheep.In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him.

let string = ''
process.stdin.setEncoding('ASCII')
process.stdin.on('data', (data) => string += data)

const main = (input) => {
    let f = input[0].split(' ').map(Number)
    let r = f[0], c = f[1]
    for (let i = 1; i < input.length; ++i) input[i] = input[i].split('')

    for (let i = 1; i <= r; ++i) {
        for (let j = 0; j < c; ++j) {
            if ( input[i][j] == '.' ) input[i][j] = 'D'
            else if (input[i][j] == 'S') {
                let adj = [[i + 1, j],[i - 1, j],[i, j + 1],[i, j - 1]]

                for (let i = 0; i < adj.length; ++i) {
                    let el = adj[i];
                    if ( el[0] >= 1 && el[0] <= r && el[1] >= 0 && el[1] < c ) {
                        if ( input[el[0]][el[1]] == 'W' ) {
                            process.stdout.write('No\n')
                            return 0
                        }
                    }
                }
            }
        }
    }

    process.stdout.write('Yes\n')
    for (let i = 1; i <= r; ++i)
        process.stdout.write( `${input[i].join('')}\n`)
}

process.stdin.on('end', () => main(string.trim().split('\n')))


The only difference between the easy and the hard version is the limit to the number of queries.This is an interactive problem.There is an array $$$a$$$ of $$$n$$$ different numbers. In one query you can ask the position of the second maximum element in a subsegment $$$a[l..r]$$$. Find the position of the maximum element in the array in no more than 40 queries.A subsegment $$$a[l..r]$$$ is all the elements $$$a_l, a_{l + 1}, ..., a_r$$$. After asking this subsegment you will be given the position of the second maximum from this subsegment in the whole array.

The first line contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$ — the number of elements in the array.

NoteIn the sample suppose $$$a$$$ is $$$[5, 1, 4, 2, 3]$$$. So after asking the $$$[1..5]$$$ subsegment $$$4$$$ is second to max value, and it's position is $$$3$$$. After asking the $$$[4..5]$$$ subsegment $$$2$$$ is second to max value and it's position in the whole array is $$$4$$$.Note that there are other arrays $$$a$$$ that would produce the same interaction, and the answer for them might be different. Example output is given in purpose of understanding the interaction.

const rl = require("readline").createInterface({
	input: process.stdin, //or fileStream
  	output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
const readln = async () => (await it.next()).value;
const writeln = (value) => process.stdout.write(`${value}\n`);
const run = async (proc)  => { await proc(); rl.close(); };

const query = async (b,e) =>
{
	if (b==e) return 0;
	writeln(`? ${b} ${e}`);
	return parseInt(await readln());
};

const outputAns = async (a) =>
{
	writeln(`! ${a}`);
};

run(async () =>
{
	const n = parseInt(await readln());
	let b = 1;
	let e = n;
	let s = await query(b,e);

	while(b!=e)
	{
		let m = Math.floor((b+e)/2);
		if (s<=m)
		{
			if ((await query(1,m))==s)
			{
				e = m;
			}
			else
			{
				b = m+1;
			}
		}
		else
		{
			if ((await query(m+1,n))==s)
			{
				b = m+1;
			}
			else
			{
				e = m;
			}
		}
	}

	outputAns(b);
});

let gotN = false;
let clarif = false;
let n,b,e,lastA;

process.stdin.on("data",(c) =>
{
	if (!gotN)
	{
		n = parseInt(c);
		gotN = true;
		b = 1;
		e = n;
		calc();
	}
	else
	{
		let a = parseInt(c);
		if (clarif)
		{
			if (a==lastA)
			{
				e = lastA-1;
			}
			else
			{
				b = lastA+1;
			}
			clarif = false;
			calc();
		}
		else
		{
			if (a==b)
			{
				b++;
				calc();
			}
			else if (a==e)
			{
				e--;
				calc();
			}
			else
			{
				clarif = true;
				lastA = a;
				process.stdout.write(`? ${b} ${a}\n`);
			}
		}
	}
});

function calc()
{
	if (b==e)
	{
		process.stdout.write(`! ${b}\n`);
	}
	else
	{
		process.stdout.write(`? ${b} ${e}\n`);
	}
}


User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.  At first, the score is 0.  For each block of contiguous "o"s with length x the score increases by x2.  For each block of contiguous "x"s with length y the score decreases by y2.   For example, if a = 6, b = 3 and ainta have arranged the cards in the order, that is described by string "ooxoooxxo", the score of the deck equals 22 - 12 + 32 - 22 + 12 = 9. That is because the deck has 5 blocks in total: "oo", "x", "ooo", "xx", "o".User ainta likes big numbers, so he wants to maximize the score with the given cards. Help ainta make the score as big as possible. Note, that he has to arrange all his cards.

The first line contains two space-separated integers a and b (0 ≤ a, b ≤ 105; a + b ≥ 1) — the number of "o" cards and the number of "x" cards.

In the first line print a single integer v — the maximum score that ainta can obtain. In the second line print a + b characters describing the deck. If the k-th card of the deck contains "o", the k-th character must be "o". If the k-th card of the deck contains "x", the k-th character must be "x". The number of "o" characters must be equal to a, and the number of "x " characters must be equal to b. If there are many ways to maximize v, print any. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

print(function(a, b){
	if(a===0){
		var ans=[];
		for(var i=0; i<b; i++){
			ans.push('x');
		}
		return -b*b + '\n' + ans.join('');
	}
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var ax=i===0?a:a-i+1;
		var ai=Math.max(0, i-1);
		var x=ax*ax+ai  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		// print(i, x)
		if(x>ans){
			ans=x;
			t=i;
		}else{
			//break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	// if(a!==0){

	for(var j=0, l=t===0?a:a-t+1; j<l; j++){
		sa.push('o');
	}
	// }

	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}
		// else{
		// 	break;
		// }
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;

	var aa=[];
	var bb=[];
	var sb1=repeat(bx+1, 'x');
	var sb2=repeat(bx, 'x');
	for(var i=0; i<bi; i++){
		bb.push(sb1);
	}
	for(var i=0; i<b-bi; i++){
		bb.push(sb2);
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}

print(function(a, b){
	var i, l, ans=-1e20, t=-1;

	if(b===0){
		ans=[];
		for(i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}

	for(i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;
	var sb1=repeat(bx+1, 'x');
	var sb2=repeat(bx, 'x');

	var ans2='';
	for(i=0; i<t; i++){
		ans2+= (i<bi?sb1:sb2)+(i<ai?'o':i===ai?repeat(ax, 'o'):'');
	}
	return ans+'\n'+ans2;
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}

print(function(a, b){
	var ans=[];
	var left=Math.floor(b/2);
	var right=Math.ceil(b/2);
	for(var i=0; i<left; i++){
		ans.push('x');
	}
	for(var i=0; i<a; i++){
		ans.push('o');
	}
	for(var i=0; i<right; i++){
		ans.push('x');
	}

	return (a===0 ? b*b : a*a-left*left-right*right)+'\n'+ans.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-1;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-1;
	var ax=a-ai;
	var aa=[];
	var bb=[];
	var sb=[];
	for(var i=0; i<bi; i++){
		bb.push(repeat(bx+1, 'x'));
	}
	for(var i=0; i<b-bi; i++){
		bb.push(repeat(bx, 'x'));
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}

print(function(a, b){
	if(a===0){
		var ans=[];
		for(var i=0; i<b; i++){
			ans.push('x');
		}
		return -b*b + '\n' + ans.join('');
	}
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var ax=i===0?a:a-i+1;
		var ai=Math.max(0, i-1);
		var x=ax*ax+ai  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		// print(i, x)
		if(x>ans){
			ans=x;
			t=i;
		}else{
			//break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	// if(a!==0){
	for(var j=0; j<a-t+1; j++){
		sa.push('o');
	}
	// }

	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;

	var aa=[];
	var bb=[];
	var sb1=repeat(bx+1, 'x');
	var sb2=repeat(bx, 'x');
	for(var i=0; i<bi; i++){
		bb.push(sb1);
	}
	for(var i=0; i<b-bi; i++){
		bb.push(sb2);
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}

print(function(a, b){
	var ans=[];
	var left=Math.floor(b/2);
	var right=Math.ceil(b/2);
	for(var i=0; i<left; i++){
		ans.push('x');
	}
	for(var i=0; i<a; i++){
		ans.push('o');
	}
	for(var i=0; i<right; i++){
		ans.push('x');
	}
	return (a*a-left*left-right*right)+'\n'+ans.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	var ans=[];
	for(var i=0, l=Math.floor(b/2); i<l; i++){
		ans.push('x');
	}
	for(var i=0; i<a; i++){
		ans.push('o');
	}
	for(var i=0, l=Math.ceil(b/2); i<l; i++){
		ans.push('x');
	}
	return ans.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	if(a===0){
		var ans=[];
		for(var i=0; i<b; i++){
			ans.push('x');
		}
		return -b*b + '\n' + ans.join('');
	}
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var x=(a-i)*(a-i)+i  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	// if(a!==0){
	for(var j=0; j<a-t+1; j++){
		sa.push('o');
	}
	// }

	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	var i, l, ans=-1e20, t=-1;

	if(b===0){
		ans=[];
		for(i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}

	for(i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i<=2 ? 0 : i-2;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t<=2 ? 0 : t-2;
	var ax=a-ai;
	var sb1=repeat(bx+1, 'x');
	var sb2=repeat(bx, 'x');

	var ans2='';
	for(i=0; i<t; i++){
		ans2+= (i<bi?sb1:sb2)+(i<ai?'0':i===ai?repeat(ax, 'o'):'');
	}
	return ans+'\n'+ans2;
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}

print(function(a, b){
	var ans=[];
	var left=Math.floor(b/2);
	var right=Math.ceil(b/2);
	for(var i=0; i<left; i++){
		ans.push('x');
	}
	for(var i=0; i<a; i++){
		ans.push('o');
	}
	for(var i=0; i<right; i++){
		ans.push('x');
	}

	return (a===0 ? -b*b : a*a-left*left-right*right)+'\n'+ans.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){

	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var x=(a-i)*(a-i)+i  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	if(a!==0){
		for(var j=0; j<a-t+1; j++){
			sa.push('o');
		}
	}
	// print(t)
	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){

	var ans=-1e20;
	var t=-1;
	for(var i=0,l=Math.min(a+1, b); i<l; i++){
		var bx=Math.floor(b/(i+1));
		var bi=b%(i+1);
		var x=(a-i)*(a-i)+i  -  (bx+1)*(bx+1)*bi-bx*bx*(i+1-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/(t+1));
	var aa=[];
	var bb=[];
	var sb=[];
	for(var j=0; j<bx; j++){
		sb.push('x');
	}
	sb=sb.join('');
	for(var j=0, l=t+1-b%(t+1); j<l; j++){
		bb.push(sb);
	}
	for(var j=0, l=b%(t+1); j<l; j++){
		bb.push(sb+'x');
	}
	for(var j=0; j<t-1; j++){
		aa.push('o');
	}
	var sa=[];
	if(a!==0){
		for(var j=0; j<a-t+1; j++){
			sa.push('o');
		}
	}
	// print(t)
	sa=sa.join('');
	aa.push(sa);
	aa.push('');
	var ans2=[];
	for(var j=0; j<i; j++){
		ans2.push(bb[j]);
		ans2.push(aa[j]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));

print(function(a, b){
	if(b===0){
		var ans=[];
		for(var i=0; i<a; i++){
			ans.push('o');
		}
		return a*a + '\n' + ans.join('');
	}
	var ans=-1e20;
	var t=-1;
	for(var i=1, l=Math.min(a+1, b); i<=l; i++){
		var bx=Math.floor(b/i);
		var bi=b%i;
		var ai=i-1;
		var ax=a-ai;
		var x = ax*ax+ai - (bx+1)*(bx+1)*bi - bx*bx*(i-bi);
		if(x>ans){
			ans=x;
			t=i;
		}else{
			break;
		}
	}

	var bx=Math.floor(b/t);
	var bi=b%t;
	var ai=t-1;
	var ax=a-ai;
	var aa=[];
	var bb=[];
	var sb=[];
	for(var i=0; i<bi; i++){
		bb.push(repeat(bx+1, 'x'));
	}
	for(var i=0; i<b-bi; i++){
		bb.push(repeat(bx, 'x'));
	}
	for(var i=0; i<ai; i++){
		aa.push('o');
	}
	aa.push(repeat(ax, 'o'));
	aa.push('');

	var ans2=[];
	for(var i=0; i<t; i++){
		ans2.push(bb[i]);
		ans2.push(aa[i]);
	}
	return ans+'\n'+ans2.join('');
}.apply(0, readline().split(' ').map(Number)));
function repeat(n, c){
	var s='';
	while(n--) s+=c;
	return s;
}