You are given a rooted tree consisting of $$$n$$$ vertices. Vertices are numbered from $$$1$$$ to $$$n$$$. Any vertex can be the root of a tree.A tree is a connected undirected graph without cycles. A rooted tree is a tree with a selected vertex, which is called the root.The tree is specified by an array of ancestors $$$b$$$ containing $$$n$$$ numbers: $$$b_i$$$ is an ancestor of the vertex with the number $$$i$$$. The ancestor of a vertex $$$u$$$ is a vertex that is the next vertex on a simple path from $$$u$$$ to the root. For example, on the simple path from $$$5$$$ to $$$3$$$ (the root), the next vertex would be $$$1$$$, so the ancestor of $$$5$$$ is $$$1$$$.The root has no ancestor, so for it, the value of $$$b_i$$$ is $$$i$$$ (the root is the only vertex for which $$$b_i=i$$$).For example, if $$$n=5$$$ and $$$b=[3, 1, 3, 3, 1]$$$, then the tree looks like this.    An example of a rooted tree for $$$n=5$$$, the root of the tree is a vertex number $$$3$$$. You are given an array $$$p$$$ — a permutation of the vertices of the tree. If it is possible, assign any positive integer weights on the edges, so that the vertices sorted by distance from the root would form the given permutation $$$p$$$.In other words, for a given permutation of vertices $$$p$$$, it is necessary to choose such edge weights so that the condition $$$dist[p_i]<dist[p_{i+1}]$$$ is true for each $$$i$$$ from $$$1$$$ to $$$n-1$$$. $$$dist[u]$$$ is a sum of the weights of the edges on the path from the root to $$$u$$$. In particular, $$$dist[u]=0$$$ if the vertex $$$u$$$ is the root of the tree.For example, assume that $$$p=[3, 1, 2, 5, 4]$$$. In this case, the following edge weights satisfy this permutation:  the edge ($$$3, 4$$$) has a weight of $$$102$$$;  the edge ($$$3, 1$$$) has weight of $$$1$$$;  the edge ($$$1, 2$$$) has a weight of $$$10$$$;  the edge ($$$1, 5$$$) has a weight of $$$100$$$. The array of distances from the root looks like: $$$dist=[1,11,0,102,101]$$$. The vertices sorted by increasing the distance from the root form the given permutation $$$p$$$.Print the required edge weights or determine that there is no suitable way to assign weights. If there are several solutions, then print any of them.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input data sets in the test. Each test case consists of three lines. The first of them contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). It is the number of vertices in the tree. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$). It is guaranteed that the $$$b$$$ array encodes some rooted tree. The third line contains the given permutation $$$p$$$: $$$n$$$ of different integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$). It is guaranteed that the sum of the values $$$n$$$ over all test cases in the test does not exceed $$$2 \cdot 10^5$$$.

For each set of input data print the answer on a separate line. If the solution exists, print an array of $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$, where $$$w_i$$$ is the weight of the edge that leads from $$$b_i$$$ to $$$i$$$. For the root there is no such edge, so use the value $$$w_i=0$$$. For all other vertices, the values of $$$w_i$$$ must satisfy the inequality $$$1 \le w_i \le 10^9$$$. There can be equal numbers among $$$w_i$$$ values, but all sums of weights of edges from the root to vertices must be different and satisfy the given permutation. If there are several solutions, output any of them. If no solution exists, output -1.

NoteThe first set of input data of the example is analyzed in the main part of the statement.In the second set of input data of the example, it is impossible to assign the positive weights to obtain a given permutation of vertices.

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
let n;
let b;
let p;
let root;
function solve() {
    const dist = af(n + 1).fill(INIT);
    dist[root] = 0;
    if (p[1] != root) {
        return false;
    }
    const edge = af(n + 1); // edge to parent
    edge[root] = 0;
    let tot = 1; // total distance to node
    for (let i = 2; i <= n; i++) {
        let u = p[i];
        if (dist[b[u]] == INIT) {
            return false;
        }
        edge[u] = tot - dist[b[u]];
        dist[u] = tot;
        tot++;
    }
    for (let i = 1; i <= n; i++) {
        printf("%d ", edge[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        b = af(n + 1);
        for (let i = 1; i <= n; i++) {
            b[i] = nextInt();
            if (b[i] == i) {
                root = i;
            }
        }
        p = af(n + 1);
        for (let i = 1; i <= n; i++) {
            p[i] = nextInt();
        }
        if (!solve()) {
            printf("-1\n");
        }
    }
}

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

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

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

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

		const done = new Map();
		done.set(root, 0);

		let ans = [];
		ans[root] = 0;

		let mxpth = 0;
		for (let v of p) {
			v--;
			if (v == root) {
				if (mxpth > 0) {
					ans = false;
					break;
				} else {
					continue;
				}
			}
			let u = b[v]; u--;
			if (done.has(u)) {
				const pthl = done.get(u);
				if (pthl+1 > mxpth) {
					ans[v] = 1;
					mxpth = pthl+ans[v];
					done.set(v, mxpth);
				} else {
					ans[v] = mxpth-pthl+1;
					mxpth = pthl+ans[v];
					done.set(v, mxpth);
				}
			} else {
				ans = false;
				break;
			}
		}

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

function solve(n, ps, arr) {
    ps.unshift(0)
    //
    const ans = Array(n + 1).fill(-1)
    const dist = Array(n + 1).fill(-1)
    let now = 0
    if (ps[arr[0]] !== arr[0]) return -1
    ans[arr[0]] = 0
    dist[arr[0]] = now
    for (let i = 1; i < arr.length; i++) {
        now++
        const x = arr[i]
        const p = ps[x]
        if (p === x) return -1
        if (dist[p] < 0) return -1
        dist[x] = now
        ans[x] = dist[x] - dist[p]
        if (ans[x] <= 0) return -1
    }
    ans.shift()
    return ans.join(' ')
}

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

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

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

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n] = ra();
  let B = ra(a=>a-1);
  let P = ra(a=>a-1);
  LT({n, B, P});
  // PROCESSING:
  if (B[P[0]]!=P[0])
    return -1;
  let dist = new Array(n).fill(-1);
  dist[P[0]] = 0;
  for (let i=1; i<n; i++){
    if (dist[B[P[i]]]==-1)
      return -1;
    dist[P[i]] = dist[P[i-1]]+1;
  }
  let ans = [];
  for (let i=0; i<n; i++){
    ans.push(dist[i]-dist[B[i]])
  }
  return 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 b= inputReader.readNumberArray();
    // let p = inputReader.readNumberArray();
    // b.unshift(-1);
    // let root = -1;

    // b.forEach((element, ind, arr) => {
    //   if(element == ind) root = element;
    // });

    // dist = new Array(n + 1).fill(-1);
    // dist[root] = 0;

    // if(p[0] != root) {
    //   console.log(-1);
    //   return;
    // }

    // p.every((element, ind, arr) => {
    //   if(b[element] == -1) {
    //     return false;
    //   }
    //   if(element == root) dist[ind] = 0;
    //   else dist[element] = dist[ind - 1] + 1;
    // });

    // let w = b.map((x, ind, arr) => {
    //   if(ind > 0)
    //   return dist[x] - dist[ind];
    // });

    // let ans = w.join(" ").trim();
    // console.log(ans);

    let n = inputReader.readNumber();
    let b = inputReader.readNumberArray();
    let p = inputReader.readNumberArray();
    b.unshift(-Infinity);
    p.unshift(-Infinity);
    let dist = new Array(n + 1).fill(-1);
    let root = -1;
    b.forEach((x, ind, arr) => {
      if (x == ind) root = x;
    });

    if (p[1] != root) {
      console.log(-1);
      return;
    }

    dist[root] = 0;
    for (let i = 2; i <= n; i++) {
      if (dist[b[p[i]]] == -1) {
        console.log(-1);
        return;
      }
      dist[p[i]] = dist[p[i - 1]] + 1;
    }

    let w = dist.map((x, i, a) => {
      if (i > 0) return x - dist[b[i]];
    });

    let ans = w.join(" ").trim();
    console.log(ans);
  }

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

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

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

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

		const done = new Map();
		done.set(root, 0);

		let ans = [];
		ans[root] = 0;

		let mxpth = 0;
		for (let v of p) {
			v--;
			if (v == root) continue;
			let u = b[v]; u--;
			if (done.has(u)) {
				const pthl = done.get(u);
				if (pthl+1 > mxpth) {
					ans[v] = 1;
					mxpth = pthl+ans[v];
					done.set(v, mxpth);
				} else {
					ans[v] = mxpth-pthl+1;
					mxpth = pthl+ans[v];
					done.set(v, mxpth);
				}
			} else {
				ans = false;
				break;
			}
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}


You are given an array $$$a$$$ of $$$n$$$ integers.You want to make all elements of $$$a$$$ equal to zero by doing the following operation exactly three times:  Select a segment, for each number in this segment we can add a multiple of $$$len$$$ to it, where $$$len$$$ is the length of this segment (added integers can be different). It can be proven that it is always possible to make all elements of $$$a$$$ equal to zero.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100\,000$$$): the number of elements of the array. The second line contains $$$n$$$ elements of an array $$$a$$$ separated by spaces: $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$).

The output should contain six lines representing three operations. For each operation, print two lines:   The first line contains two integers $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n$$$): the bounds of the selected segment.  The second line contains $$$r-l+1$$$ integers $$$b_l, b_{l+1}, \dots, b_r$$$ ($$$-10^{18} \le b_i \le 10^{18}$$$): the numbers to add to $$$a_l, a_{l+1}, \ldots, a_r$$$, respectively; $$$b_i$$$ should be divisible by $$$r - l + 1$$$.

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    if(n === 1){
        console.log(1,1);
        console.log(-1*a[0]);
        console.log(1,1);
        console.log(0);
        console.log(1,1);
        console.log(0);
        return;
    }
    let res = '';
    console.log(1,n);
    for(let i = 0; i < n; i++){
        res = `${res}${-1*n*a[i]} `;
    }
    console.log(res.trim());
    console.log(2,n);
    res = '';
    for(let i = 1; i < n; i++){
        res = `${res}${(n-1)*a[i]} `;
    }
    console.log(res.trim());
    console.log(1,1);
    console.log((n-1)*a[0]);
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), a = $(n), x
  if (n == 1) {
    log(`1 1\n${-a[0]}\n1 1\n0\n1 1\n0`);
    return;
  }
  out.push(`1 ${n - 1}`);
  out.push(Arr(n - 1, i => (x = (n - 1) * a[i], a[i] += x, x)).join(' '))
  out.push(`${n} ${n}`);
  out.push(a[n - 1] ? (x = n - a[n - 1] % n, a[n - 1] += x, x) : 0)
  out.push(`1 ${n}`);
  out.push(Arr(n, i => -a[i]).join(' '))
  log(out.join('\n'))
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), a = $(n), x
  if (n == 1) {
    log(`1 1\n${-a[0]}\n1 1\n0\n1 1\n0`);
    return;
  }
  out.push(`1 ${n - 1}`);
  out.push(Arr(n - 1, i => (x = (n - 1) * a[i], a[i] += x, x)).join(' '))
  out.push(`${n} ${n}`);
  out.push(a[n - 1] ? (x = n - n % a[n - 1], a[n - 1] += x, x) : 0)
  out.push(`1 ${n}`);
  out.push(Arr(n, i => -a[i]).join(' '))
  log(out.join('\n'))
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    let res = '';
    console.log(1,n);
    for(let i = 0; i < n; i++){
        res = `${res}${-1*n*a[i]} `;
    }
    console.log(res.trim());
    console.log(2,n);
    res = '';
    for(let i = 1; i < n; i++){
        res = `${res}${(n-1)*a[i]} `;
    }
    console.log(res.trim());
    console.log(1);
    console.log((n-1)*a[0]);
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    let res = '';
    console.log(1,n);
    for(let i = 0; i < n; i++){
        res = `${res}${-1*n*a[i]} `;
    }
    console.log(res.trim());
    console.log(2,n);
    res = '';
    for(let i = 1; i < n; i++){
        res = `${res}${(n-1)*a[i]} `;
    }
    console.log(res.trim());
    console.log(1,1);
    console.log((n-1)*a[0]);
}


It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.There are $$$n$$$ displays placed along a road, and the $$$i$$$-th of them can display a text with font size $$$s_i$$$ only. Maria Stepanovna wants to rent such three displays with indices $$$i < j < k$$$ that the font size increases if you move along the road in a particular direction. Namely, the condition $$$s_i < s_j < s_k$$$ should be held.The rent cost is for the $$$i$$$-th display is $$$c_i$$$. Please determine the smallest cost Maria Stepanovna should pay.

The first line contains a single integer $$$n$$$ ($$$3 \le n \le 3\,000$$$) — the number of displays. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the font sizes on the displays in the order they stand along the road. The third line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le 10^8$$$) — the rent costs for each display.

If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $$$i < j < k$$$ such that $$$s_i < s_j < s_k$$$.

NoteIn the first example you can, for example, choose displays $$$1$$$, $$$4$$$ and $$$5$$$, because $$$s_1 < s_4 < s_5$$$ ($$$2 < 4 < 10$$$), and the rent cost is $$$40 + 10 + 40 = 90$$$.In the second example you can't select a valid triple of indices, so the answer is -1.

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}
const INF = Number.MAX_SAFE_INTEGER

main()

function main() {
  const n = getInt()
  const arr = getInts()
  const cost = getInts()

  let ans = INF
  for (let i = 1; i < n; ++i) {
    let l = INF
    let r = INF
    for (let j = i - 1; j >= 0; --j) {
      if (arr[j] < arr[i]) {
        l = Math.min(l, cost[j])
      }
    }

    for (let j = i + 1; j < n; ++j) {
      if (arr[j] > arr[i]) {
        r = Math.min(r, cost[j])
      }
    }

    ans = Math.min(ans, l + r + cost[i])
  }
  print(ans === INF ? -1 : ans)
}


In this problem, your task is to use ASCII graphics to paint a cardiogram. A cardiogram is a polyline with the following corners:That is, a cardiogram is fully defined by a sequence of positive integers a1, a2, ..., an.Your task is to paint a cardiogram by given sequence ai.

The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.

Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print  characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram. Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.

NoteDue to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.http://assets.codeforces.com/rounds/435/1.txthttp://assets.codeforces.com/rounds/435/2.txt

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		level = 0, minLevel = 0, maxLevel = 0, direction = 1,
		length = 0;
	for (var i = 0; i < n; ++i) {
		level += direction*(data[i]-1);
		minLevel = Math.min(minLevel, level);
		maxLevel = Math.max(maxLevel, level);
		direction *= -1;
		length += data[i];
	}
	var height = maxLevel - minLevel + 1;
	var g = new Array(height);
	for (var r = 0; r < height; ++r) {
		g[r] = new Array(length);
		for (var c = 0; c < length; ++c) {
			g[r][c] = ' ';
		}
	}
	var r = height-1+minLevel, c = 0, direction = -1, ch = '/',
		opposite = { "\\": "/", "/": "\\" };
	for (var i = 0; i < n; ++i) {
		var d = data[i];
		g[r][c++] = ch;
		for (var j = 1; j < d; ++j) {
			r += direction;
			g[r][c++] = ch;
		}
		direction *= -1;
		ch = opposite[ch];
	}
	var lines = [];
	for (var r = 0; r < height; ++r) {
		lines.push(g[r].join(''));
	}
	print(lines.join('\n'));
}

main();


Luca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types:   up move (denoted by $$$\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes $$$0$$$.  down move (denoted by $$$\texttt{D}$$$): it decreases the $$$i$$$-th digit by $$$1$$$. After applying the down move on $$$0$$$, it becomes $$$9$$$.     Example for $$$n=4$$$. The current sequence is 0 0 0 0. Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of wheels. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 9$$$) — the digit shown on the $$$i$$$-th wheel after all moves have been performed. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains the integer $$$b_i$$$ ($$$1 \leq b_i \leq 10$$$) and $$$b_i$$$ characters that are either $$$\texttt{U}$$$ or $$$\texttt{D}$$$ — the number of moves performed on the $$$i$$$-th wheel, and the moves performed. $$$\texttt{U}$$$ and $$$\texttt{D}$$$ represent an up move and a down move respectively.

For each test case, output $$$n$$$ space-separated digits  — the initial sequence of the cypher.

3

3

9 3 1

3 DDD

4 UDUU

2 DU

2

0 9

9 DDDDDDDDD

9 UUUUUUUUU

5

0 5 9 8 3

10 UUUUUUUUUU

3 UUD

8 UUDUUDDD

10 UUDUUDUDDU

4 UUUU

NoteIn the first test case, we can prove that initial sequence was $$$[2,1,1]$$$. In that case, the following moves were performed:   On the first wheel: $$$2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$$$.  On the second wheel: $$$1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$$$.  On the third wheel: $$$1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$$$.  The final sequence was $$$[9,3,1]$$$, which matches the input.

const main = (input) => {
  input = input.split('\n')

  const t = parseInt(input[0])
  let cnt = 0
  for (let i = 0; i < t; i++) {
    const n = parseInt(input[1 + cnt + 2 * i])
    const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))

    let ans = [...a]
    for (let j = 0; j < n; j++) {
      const [_, b] = input[1 + cnt + 2 * i + 2 + j].trim().split(' ')
      const d = Array.from(b).reduce(
        (prev, current) => prev + (current === 'U' ? -1 : 1),
        0
      )
      ans[j] += d
      ans[j] %= 10
      ans[j] += 10
      ans[j] %= 10
    }
    console.log(ans.map((x) => String(x)).join(' '))

    cnt += n
  }
}

main(require('fs').readFileSync(0).toString())

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    let arr = [];
    while (b--) {
      arr.push(readLine());
    }
    var res = solveMeFirst(arr, c);
    let out = "";
    if (res) {
      for (let i = 0; i < res.length; i++) {
        out += res[i] + " ";
      }
      console.log(out);
    }
  }
}
function solveMeFirst(arr, str) {
  str = str.split(" ");
  for (let i = 0; i < arr.length; i++) {
    let cnt = 0;
    for (let j = 2; j < arr[i].length; j++) {
      if (arr[i][j] === "D") {
        cnt++;
      }
      if (arr[i][j] === "U") {
        cnt--;
      }
    }
    str[i] = +str[i];
    str[i] += cnt;
    if (str[i] < 0) {
      let temp = str[i] / 10;
      str[i] = Math.round((temp + 1) * 10);
    }
    str[i] %= 10;
  }
  return str;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

function Solution() {
  let t = 0;
  const N = Number(lines[t++]);
  const R = [];
  for (let i = 0; i < N; i++) {
    const n = Number(lines[t++]);
    const initArr = lines[t++].split(' ').map((item) => Number(item));
    for (let j = 0; j < n; j++) {
      const [numStr, str] = lines[t++].split(' ');
      const num = Number(numStr);
      for (let z = 0; z < num; z++) {
        if (str[z] === 'D') initArr[j] = (initArr[j] + 1) % 10;
        else initArr[j] = (initArr[j] - 1 + 10) % 10;
      }
    }
    R.push(initArr.join(' '));
  }
  return R.join('\n');
}

const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
const lines = []
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', () => {
  console.log(Solution());
});

function Solution() {
  let t = 0;
  const N = Number(lines[t++]);
  const R = [];
  for (let i = 0; i < N; i++) {
    const n = Number(lines[t++]);
    const initArr = lines[t++].split(' ').map((item) => Number(item));
    const res = [];
    for (let j = 0; j < n; j++) {
      const [numStr, str] = lines[t++].split(' ');
      const num = Number(numStr);
      let count = 0;
      for (let z = 0; z < num; z++) {
        if (str[z] === 'D') count += 1;
        else count -=1;
      }
      const target = initArr[j] + count;
      res[j] = target >= 0 ? target % 10 : (target % 10 + 10) % 10;
    }
    R.push(res.join(' '));
  }
  return R.join('\n');
}

const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
const lines = []
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', () => {
  console.log(Solution());
});

const rdline = require('readline');

const rl = rdline.createInterface({
    input: process.stdin
});

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];

solve = () => {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var m = [];
        var n = parseInt(readline());
        var s = readline().split().join().replace(/\s/g, '');
        for (var j = 0; j < n; j++) {
            var z = parseInt(s[j]);
            var b = readline();
            var p = b.split(' ')[1];
            for (let k = 0; k < p.length; k++) {
                if (p[k] === 'U') {
                    if (z === 0) {
                        z = 9;
                    } else {
                        z--;
                    }
                }
                    if (p[k] === 'D') {
                        if (z === 9) {
                            z = 0;
                        } else {
                            z++;
                        }
                    }
            }
            m[j] = z;
        }
        console.log(m.join(' '));
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
      let n = parseInt(readline());
      let s = readline().split(' ');

      let data = Array(n);
      let res = [];
      for (let i = 0; i < n;++i) {
        res.push(parseInt(s[i]));
        data[i] = readline().split(' ');
      }
      for (let i = 0; i < n;++i) {
        for (let j = 0;j < data[i][1].length; ++j) {
          if (data[i][1].charAt(j) === 'U') {
            res[i] = (res[i]-1+10)%10;
          } else if (data[i][1].charAt(j) === 'D') {
            res[i] = (res[i]+1+10)%10;
          }
        }
      }
      var ress = res.join(' ').toString();
      console.log(ress);
    }
}

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

function solve(n, arr, move) {
    return arr.map((x, i) => {
        move[i] = move[i][1]
        for (let j = 0; j < move[i].length; j++) {
            const d = move[i][j] === 'D' ? -1 : 1
            x -= d
        }
        x = x % 10
        x = (x + 10) % 10
        return x
    }).join(' ')
}

// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
'use strict';
let data = ''; // raw
let inputs = ''; // iterator
function read() {
    return inputs.next().value.trim();
};
const update = (v, dir) => {
    if (dir == 'D') {
        if (v == 9) return 0
        return v + 1
    }
    if (dir == 'U') {
        if (v == 0) return 9
        return v - 1
    }
}
async function main(read) {
    try {
        let tasks = parseInt(await read())
        let result = []
        let current_combination = null
        for (let i = 0; i < tasks; i++) {
            const sub_length = parseInt(await read())
            current_combination = (await read()).split(' ').map(Number)
            for (let j = 0; j < sub_length; j++) {
                const element = (await read());
                const [num, content] = element.split(' ')
                for (let k = 0; k < content.length; k++) {
                    const element = content[k];
                    current_combination[j] = update(current_combination[j], element)
                }
            }
            result[i] = current_combination.join(' ')
        }
        return result.join('\n')
    } catch (error) {
        console.log(error);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    inputs = data.split('\n').values();
    const result = await main(read);
    // console.log(result)
    process.stdout.write(result);
});

process.stdin.resume();
process.stdin.setEncoding("ascii");

_input = "";
process.stdin.on("data", function (input) {
   _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

function processData(input) {
    const lines = input.split("\n");
    let startLine = 1;
    for (let i = 1; i <= lines[0]; i++) {
      startLine = processTC(lines, startLine);
    }
}

function processTC(lines, startLine) {
    const n = Number(lines[startLine]);
    const seq = lines[startLine+1].split(" ").map(x => Number(x));
    let str = "";
    for (let i = 0; i < n; i++) {
      const num = startLine+2+i;
      const [stepsN, steps] = lines[num].split(" ");
      const res = getInitialDigit(seq[i], steps, stepsN);
      str += res + " ";
    }
    console.log(str.trim());
    return startLine+(n+2);
}

function getInitialDigit(num, steps, n) {
  for (let i = 0; i < n; i++) {
    const diff = steps.charAt(i) === "U" ? -1 : 1;
    num=num+diff;
    if (num===10) num = 0;
    if (num===-1) num = 9;
  }
  return num;
}

'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() {
  let times = parseInt(readline());
  for (let i = 0; i < times; i++) {
    let cellNumber = parseInt(readline());
    let cellFinal = readline()
      .split(' ')
      .map((number) => {
        return parseInt(number);
      });
    for (let j = 0; j < cellNumber; j++) {
      let counter = 0;
      let [len, str] = readline().split(' ');
      for (let char of str) {
        counter += char === 'D' ? 1 : -1;
      }
      cellFinal[j] = (cellFinal[j] + (counter % 10)) % 10;
      if (cellFinal[j] < 0) {
        cellFinal[j] += 10;
      }
    }
    console.log(...cellFinal);
  }
}

"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 arr1 = [];
    for (let i = 0; i < n; i++) {
      arr1.push(readline().trim().split(" "));
    }
    for (let i = 0; i < n; i++) {
      let x = arr1[i][1];
      for (let j = 0; j < x.length; j++) {
        if (x[j] === "U") {
          if (arr[i] === 0) arr[i] = 9;
          else arr[i] = (arr[i] - 1) % 10;
        } else arr[i] = (arr[i] + 1) % 10;
      }
    }
    let res = "";
    for (let i = 0; i < n; i++) res += arr[i] + " ";
    console.log(res);
  }
};
solve();

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
// console.log(input)
var T = readline();
// var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  var a = readline().split(' ').map((x) => parseInt(x));
  var ans = [];
  for(var i=0;i<n;i++) {
    var [c, b] = readline().split(" ");
    // if(tc == 1) console.log(b)
    var res = a[i];
    for(var j=0;j<c;j++) {
      if(b[j] == "U") {
        res = (res-1)%10;
        if(res < 0) res = (res+10)%10
      } else {
        res = (res+1)%10;
      }
    }
    ans.push(res)
  }
  console.log(ans.join(" "))
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        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++) {
        const mapVal = char => char === 'D' ? -1 : 1;
        const n = Number(readline());
        const digits = readline().split(' ').map(Number);
        let seq = new Array(n);
        for (let i = 0; i < n; i++) {
            seq[i] = readline().split(' ')[1];
            seq[i] = (digits[i] - seq[i].split('').map(mapVal).reduce((a, b) => a + b, 0) + 100) % 10;
        }

        let res = seq.map(String).join(' ');
        output(res);
    }
}

//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 = 0; i < N; i++){
			var c = nextInt();
			var cy = next();
			for(var j = 0; j < c; j++){
				if(cy[j] == "U"){
					list[i]--;
				}else{
					list[i]++;
				}
				list[i] += 10;
				list[i] %= 10;
			}
		}
		myout(myconv(list, 8));
	}
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var seq = readline().split(" ");

    for (var j = 0; j < n; j++) {
        var str = readline().split(" ");

        for (var k = 0; k < str[0]; k++) {
            if (str[1][k] === "D") {
                seq[j]++;
            } else if (str[1][k] === "U") {
                seq[j]--;
            }
        }

        seq[j] = (seq[j] + 10) % 10;
    }

    print(seq.join(" "));
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var wheels = parseInt(readline());
    var caseArray = readline().split(" ");
    var result = "";
    for (var j = 0; j < wheels; j++)
    {
        var current = readline().split(" ");
        var value = parseInt(caseArray[j]);
        for (var k = 0; k < parseInt(current[0]); k++)
        {
            if (current[1][k] == 'D')
            {
                if (value === 9) value = 0; else value++;
            }
            else if (value === 0) value = 9; else value--;
        }
        result += `${value} `;
    }
    print(result);
}

T = readline()

while(T--){
      n = readline()
      x = readline().split(' ')

      for(j=0;j<n;j++){
            str = readline().split('')
            b = str[0]
            b1 = str[1]
            str.shift()
            str.shift()

            if(str.length == 11){
                  str.shift()
                  b = 10
            }

            for(i = 0; i<b; i++){
                  if(str[i] == 'U'){
                        if(x[j] == 0)
                              x[j] = 9
                        else
                              x[j]--
                  }
                  if(str[i] == 'D'){
                        if(x[j] == 9)
                              x[j] = 0
                        else
                              x[j]++
                  }
            }
      }

      print(x.join(' '))
}

var t = +readline();

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

      var nums = [];
    var t1 = +readline();
    var t2 = readline().split(' ').map((t) => +t);
    for(var k = 0; k < t1; k++){
      var t3 = readline().split(' ');
      nums.push(t3[1])
    }
    print(Cypher(t2,nums));

}

function Cypher(nums,arr){

   var res = [];
  for(var i = 0; i<nums.length; i++){
    res.push(nums[i])
  }
  for(var j = 0; j<arr.length; j++){
    var test = res[j];
    for(var each of arr[j]){
      test += each == 'D' ? 1 : -1;
      if (test == 10) test = 0;
      else if (test == -1){
        test = 9;
      }
    }
    res[j] = test;
  }
  return res.join(' ')
}

function decrypt(pattern, n){
    var k = pattern.split(' ')[1].split('');
    for(var j=k.length-1; j>=0; j--){
        if(k[j] == 'D'){
            if(n==9)n=0;
            else n++;
        }else{
            if(n==0)n=9;
            else n--;
        }
    }
    return n;
}

var test = readline()

for(var i=0; i<test; i++){
    var n = readline();
    var cyper = readline().split(' ');
    var whele = [];
    for(var j=1; j<=n; j++){
        whele.push(readline());
    }
    var result = '';
    for(var j=0; j<n; j++){
        result  += (decrypt(whele[j], cyper[j]))+ ' ';
    }
    print(result)
}

var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var n = parseInt(readline());
        var a = readline().split(' ').map(x => parseInt(x));
        var ans = [];
        for (var i =0; i < n; i++) {
            var line = readline().split(' ');
            var seq = line[1];
            var f = a[i];
            for (var j = seq.length-1; j >= 0; j--) {
                if (seq[j] == 'D') {
                    f = (f + 1)%10;
                } else {
                    f = f-1;
                    if (f < 0) {
                        f = 9;
                    }
                }
            }
            ans.push(f);
        }
        print(ans.join(' '));
    }

const main = (input) => {
  input = input.split('\n')

  const t = parseInt(input[0])
  let cnt = 0
  for (let i = 0; i < t; i++) {
    const n = parseInt(input[1 + cnt + 2 * i])
    const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))

    let ans = [...a]
    for (let j = 0; j < n; j++) {
      const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')
      console.log('b:', b)
      const d = Array.from(b).reduce(
        (prev, current) => prev + (current === 'U' ? -1 : 1),
        0
      )
      console.log('d:', d)
      ans[j] += d
      ans[j] %= 10
      ans[j] += 10
      ans[j] %= 10
    }
    console.log(ans.map((x) => String(x)).join(' '))

    cnt += n
  }
}

main(require('fs').readFileSync(0).toString())

const main = (input) => {
  input = input.split('\n')

  const t = parseInt(input[0])
  let cnt = 0
  for (let i = 0; i < t; i++) {
    const n = parseInt(input[1 + cnt + 2 * i])
    const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))

    let ans = [...a]
    console.log('ans:', ans)
    for (let j = 0; j < n; j++) {
      const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')
      const d = Array.from(b).reduce(
        (prev, current) => prev + (current === 'U' ? -1 : 1),
        0
      )
      console.log('d:', d)
      ans[j] += d
      ans[j] %= 10
      ans[j] += 10
      ans[j] %= 10
    }
    console.log(ans.map((x) => String(x)).join(' '))

    cnt += n
  }
}

main(require('fs').readFileSync(0).toString())

const main = (input) => {
  input = input.split('\n')

  const t = parseInt(input[0])
  let cnt = 0
  for (let i = 0; i < t; i++) {
    const n = parseInt(input[1 + cnt + 2 * i])
    const a = input[1 + cnt + 2 * i + 1].split(' ').map((x) => parseInt(x))

    let ans = [...a]
    for (let j = 0; j < n; j++) {
      const [_, b] = input[1 + cnt + 2 * i + 2 + j].split(' ')
      const d = Array.from(b).reduce(
        (prev, current) => prev + (current === 'U' ? -1 : 1),
        0
      )
      ans[j] += d
      ans[j] += 10
      ans[j] %= 10
    }
    console.log(ans.map((x) => String(x)).join(' '))

    cnt += n
  }
}

main(require('fs').readFileSync(0).toString())

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    let arr = [];
    while (b--) {
      arr.push(readLine());
    }
    var res = solveMeFirst(arr, c);
    let out = "";
    if (res) {
      for (let i = 0; i < res.length; i++) {
        out += res[i] + " ";
      }
      console.log(out);
    }
  }
}
function solveMeFirst(arr, str) {
  str = str.split(" ");
  for (let i = 0; i < arr.length; i++) {
    let cnt = 0;
    for (let j = 2; j < arr[i].length; j++) {
      if (arr[i][j] === "D") {
        cnt++;
      }
      if (arr[i][j] === "U") {
        cnt--;
      }
    }
    str[i] = +str[i];
    str[i] += cnt;
    if (str[i] < 0) {
      let temp = str[i] / 10;
      str[i] = (temp + 1) * 10;
    }
    str[i] %= 10;
  }
  return str;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.on("SIGINT", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    let arr = [];
    while (b--) {
      arr.push(readLine());
    }
    var res = solveMeFirst(arr, c);
    let out = "";
    if (res) {
      for (let i = 0; i < res.length; i++) {
        out += res[i] + " ";
      }
      console.log(out);
    }
  }
}
function solveMeFirst(arr, str) {
  str = str.split(" ");
  for (let i = 0; i < arr.length; i++) {
    let cnt = 0;
    for (let j = 2; j < arr[i].length; j++) {
      if (arr[i][j] === "D") {
        cnt++;
      }
      if (arr[i][j] === "U") {
        cnt--;
      }
    }
    str[i] = +str[i];
    str[i] += cnt;
    if (str[i] < 0) {
      let temp = str[i] / 10;
      str[i] = (temp + 1) * 10;
    }
    str[i] %= 10;
  }
  return str;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function swap(arr, i, j) {
  let temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    let arr = [];
    while (b--) {
      arr.push(readLine());
    }
    var res = solveMeFirst(arr, c);
    let out = "";
    if (res) {
      for (let i = 0; i < res.length; i++) {
        out += res[i] + " ";
      }
      console.log(out);
    }
  }
}
function solveMeFirst(arr, str) {
  str = str.split(" ");
  for (let i = 0; i < arr.length; i++) {
    for (let j = 2; j < arr[i].length; j++) {
      if (arr[i][j] === "D") {
        if (str[i] == "9") str[i] = 0;
        else str[i]++;
      }
      if (arr[i][j] === "U") {
        if (str[i] == "0") str[i] = 9;
        else str[i] = Math.abs(str[i] - 1);
      }
    }
  }
  return str;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function swap(arr, i, j) {
  let temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var c = readLine();
    let arr = [];
    while (b--) {
      arr.push(readLine());
    }
    var res = solveMeFirst(arr, c);
    let out = "";
    if (res) {
      for (let i = 0; i < res.length; i++) {
        out += res[i] + " ";
      }
      console.log(out);
    }
  }
}
function solveMeFirst(arr, str) {
  str = str.split(" ");
  for (let i = 0; i < arr.length; i++) {
    for (let j = 2; j < arr[i].length; j++) {
      if (arr[i][j] === "D") {
        str[i]++;
      }
      if (arr[i][j] === "U") {
        if (str[i] == "0") str[i] = 9;
        else str[i] = Math.abs(str[i] - 1);
      }
    }
    str[i] = str[i] % 10;
  }
  return str;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var seq = readline().split(" ");

    for (var j = 0; j < n; j++) {
        var str = readline().split(" ");

        for (var k = 0; k < str[0]; k++) {
            if (str[1][k] === "D") {
                seq[j]++;
            } else if (str[1][k] === "U") {
                seq[j]--;
            }
        }

        seq[j] %= 10;
    }

    print(seq);
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var seq = readline().split(" ");

    for (var j = 0; j < n; j++) {
        var str = readline().split(" ");

        for (var k = 0; k < str[0]; k++) {
            if (str[1][k] === "D") {
                seq[n]++;
            } else if (str[1][k] === "U") {
                seq[n]--;
            }
        }

        seq[j] %= 10;
    }

    print(seq);
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
    var n = parseInt(readline());
    var seq = readline().split(" ");

    for (var j = 0; j < n; j++) {
        var str = readline().split(" ");

        for (var k = 0; k < str[0]; k++) {
            if (str[1][k] === "D") {
                seq[n]++;
            } else if (str[1][k] === "U") {
                seq[n]--;
            }
        }

        seq[n] %= 10;
    }

    print(seq);
}

T = readline()

while(T--){
      n = readline()
      x = readline().split(' ')

      for(j=0;j<n;j++){
            str = readline().split('')
            b = str[0]
            str.shift()
            str.shift()

            for(i = 0; i<b; i++){
                  if(str[i] == 'U'){
                        if(x[j] == 0)
                              x[j] = 9
                        else
                              x[j]--
                  }
                  if(str[i] == 'D'){
                        if(x[j] == 9)
                              x[j] = 0
                        else
                              x[j]++
                  }
            }
      }

      print(x.join(' '))
}

T = readline()

while(T--){
      n = readline()
      x = readline().split(' ')

      for(j=0;j<n;j++){
            str = readline().split('')
            b = str[0]
            str.shift()
            str.shift()

            for(i = 0; i<b; i++){
                  if(str[i] === 'U'){
                        if(x[j] === 9){
                              x[j] = 0
                        }
                        else
                              x[j]++
                  }
                  if(str[i] === 'D'){
                        if(x[j] === 0){
                              x[j] = 9
                        }
                        else
                              x[j]--
                  }
            }
      }
      print(x.join(' '))
}

var t = +readline();

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

      var nums = [];
    var t1 = +readline();
    var t2 = readline().split(' ').map((t) => +t);
    for(var k = 0; k < t1; k++){
      var t3 = readline().split(' ');
      nums.push(t3[1])
    }
    print(Cypher(t2,nums));

}

function Cypher(nums,arr){

  var res = [];
  for(var i = 0; i<nums.length; i++){
    res.push(nums[i])
  }
  for(var j = 0; j<arr.length; j++){
    var test = 0;
    for(var each of arr[j]){
      test += each == 'D' ? 1 : -1;
    }
    res[j] = Math.abs((res[j] + test) % 10);
  }
  return res.join(' ')
}


Word $$$s$$$ of length $$$n$$$ is called $$$k$$$-complete if   $$$s$$$ is a palindrome, i.e. $$$s_i=s_{n+1-i}$$$ for all $$$1 \le i \le n$$$;  $$$s$$$ has a period of $$$k$$$, i.e. $$$s_i=s_{k+i}$$$ for all $$$1 \le i \le n-k$$$. For example, "abaaba" is a $$$3$$$-complete word, while "abccba" is not.Bob is given a word $$$s$$$ of length $$$n$$$ consisting of only lowercase Latin letters and an integer $$$k$$$, such that $$$n$$$ is divisible by $$$k$$$. He wants to convert $$$s$$$ to any $$$k$$$-complete word.To do this Bob can choose some $$$i$$$ ($$$1 \le i \le n$$$) and replace the letter at position $$$i$$$ with some other lowercase Latin letter.So now Bob wants to know the minimum number of letters he has to replace to convert $$$s$$$ to any $$$k$$$-complete word.Note that Bob can do zero changes if the word $$$s$$$ is already $$$k$$$-complete.You are required to answer $$$t$$$ test cases independently.

The first line contains a single integer $$$t$$$ ($$$1 \le t\le 10^5$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k < n \le 2 \cdot 10^5$$$, $$$n$$$ is divisible by $$$k$$$). The second line of each test case contains a word $$$s$$$ of length $$$n$$$. It is guaranteed that word $$$s$$$ only contains lowercase Latin letters. And it is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.

For each test case, output one integer, representing the minimum number of characters he has to replace to convert $$$s$$$ to any $$$k$$$-complete word.

4
6 2
abaaba
6 3
abaaba
36 9
hippopotomonstrosesquippedaliophobia
21 7
wudixiaoxingxingheclp

NoteIn the first test case, one optimal solution is aaaaaa.In the second test case, the given word itself is $$$k$$$-complete.

// const SegmentTree = require('javascript-algo-ds/src/data-structure/trees/segmentTree/segmentTree')
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

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

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

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

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

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

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const [n, k] = readInts()
    const s = ("#" + readString()).split('')
    const half = Math.ceil(k / 2)
    let total = 0
    for(let i = 1; i <= half; i++) {
      const alpha = new Array(26).fill(0)
      let count = 0
      for(let j = i; j <= n; j+= k) {
        alpha[s[j].charCodeAt(0) - 97]++
        count++
      }
      if(k % 2 === 0 || i !== half) {
        for(let j = n - i + 1; j >= 1; j-= k) {
          alpha[s[j].charCodeAt(0) - 97]++
          count++
        }
      }
      total += count - Math.max(...alpha)
      // wr(alpha, count, Math.max(...alpha), i)
    }
    wr(total)
  }
}


Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > au, where au is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?

In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree. In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i. The next n - 1 lines describe tree edges: ith of them consists of two integers pi and ci (1 ≤ pi ≤ n,  - 109 ≤ ci ≤ 109), meaning that there is an edge connecting vertices i + 1 and pi with number ci written on it.

Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.

NoteThe following image represents possible process of removing leaves from the tree:

var n=+readline(),a=readline().split(' '),i,b=new Array(n),t=[],j=0;
for(i=1;i<n;++i){
  t=readline().split(' ');
  j=t[0]-1; t=+t[1];
  if(!b[j])b[j]=new Map();
  if(!b[i])b[i]=new Map();
  b[j].set(i,t);
  b[i].set(j,t);
}
function dfs(n,s){
  var r=a[n]<s,k=0,t=b[n],i=t.size;
  for(;i<2;){
    if(!i)return +r;
    if(r)return count(n);
    if(s<0)s=0;
    t=t.entries().next().value;
    b[t[0]].delete(n);
    n=t[0]; s+=t[1];
    r=a[n]<s;
    t=b[n]; i=t.size;
  }
  if(r)return count(n);
  if(s<0)s=0;
  for(i of t.entries()){
    b[i[0]].delete(n);
    k+=dfs(i[0],s+i[1]);
  }
  return k;
}
function count(n){
  var i,st=[n],k=0;
  for(;st.length;++k)
    for(i of b[n=st.pop()].keys())b[i].delete(n),st.push(i);
  return k;
}
print(dfs(0,-Infinity));

var n=+readline(),a=readline().split(' '),k=0,i,b=new Array(n),t=[],j=0;
for(i=1;i<n;++i){
  t=readline().split(' ');
  j=t[0]-1;
  if(!b[j])b[j]=[];
  if(!b[i])b[i]=[];
  b[j][i]=b[i][j]=+t[1];
}
function dfs(n,s){
  var i;
  if(a[n]<s)++k;
  for(i in b[n]){
    delete b[i][n];
    dfs(i,s+b[n][i]);
  }
}
dfs(0,0);
print(k);


Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!We say that a string formed by $$$n$$$ characters '(' or ')' is simple if its length $$$n$$$ is even and positive, its first $$$\frac{n}{2}$$$ characters are '(', and its last $$$\frac{n}{2}$$$ characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'. Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?A sequence of characters $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The only line of input contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$) formed by characters '(' and ')', where $$$|s|$$$ is the length of $$$s$$$.

In the first line, print an integer $$$k$$$  — the minimum number of operations you have to apply. Then, print $$$2k$$$ lines describing the operations in the following format: For each operation, print a line containing an integer $$$m$$$  — the number of characters in the subsequence you will remove. Then, print a line containing $$$m$$$ integers $$$1 \le a_1 < a_2 < \dots < a_m$$$  — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string. If there are multiple valid sequences of operations with the smallest $$$k$$$, you may print any of them.

NoteIn the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices $$$2$$$ and $$$3$$$, which results in the same final string.In the second sample, it is already impossible to perform any operations.

var str = readline().split('');
var i = 0;
var j = str.length - 1;
var result = [];
while (i < j) {
    if (str[i] === '(') {
        if (str[j] === ')') {
            result.push(i+1);
            result.push(j+1);
            i++;
            j--;
        }
        else {
            j--;
        }
    }
    else {
        i++;
    }
}
if (result.length) {
    result = result.sort((a,b) => a - b);
    print('1');
    print(result.length);
    print(result.join(' '));
} else {
    print('0');
}

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

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

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

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

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

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

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

function main(input) {
  const s = input[0]
  const len = s.length
  let i = 0, j = len - 1
  let ans = []
  while(i <= j) {
    if(s[i] === '(' && s[j] === ')') {
      ans.push(j + 1)
      ans.unshift(++i)
      j--
    }
    else if(s[i] !== '(') i++
    else if(s[j] !== ')') j--
  }
  if(ans.length === 0) wr(0)
  else {
    sort(ans)
    wr(1)
    wr(ans.length)
    wr(ans.join(' '))
  }
}

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

    function foo (str) {
        let k = 0;
        let aResult = [];
        let result = [];

        let lft = 0;
        let rght = str.length - 1;

        while (lft < rght) {
            if (str[lft] === '(') {
                while(lft < rght) {
                    if (str[rght] === ')') {
                        result.push(lft + 1);
                        result.push(rght + 1);
                        lft++;
                        rght--;
                        break;
                    } else {
                        rght--;
                    }
                }

            } else {
                lft++
            }
        }

        result.sort((a, b) => a - b);

        if (result.length) {
            aResult[0] = result;
            k++;
            const resSet = new Set(result);
            const subStr = str.split('').filter((v, index) => !resSet.has(index + 1)).join('');
            const subRes = foo(subStr);

            if (subRes[0] !== 0) {
                k = k + subRes[0];
                aResult = aResult.concat(subRes[1])
            }
        }
        return [k, aResult];
    }

    let result = foo(lines[0]);
    console.log(result[0]);
    if (result[1].length) {
        let answer = '';
        result[1].forEach(v => answer += v.length + '\n' + v.join(' ') + '\n');
        console.log(answer);
    }
})

const processData = (lines) => {
  const str = lines[0]
  let refinedStr = str.slice(0)
  const ops = []
  let size = 0
  let index = []
  const left = []
  const right = []
  for (let j =0; j<str.length; j++) {
    const ch = str[j]
    switch(ch) {
      case '(':
        left.push(j)
        break
      case ')':
        right.push(j)
        break
    }
  }
  let rightCounter = right.length - 1
  let leftCounter = 0
  let acc = []
  while(rightCounter >= 0 && leftCounter < left.length) {
    const leftPos = left[leftCounter]
    let rightPos = right[rightCounter]
    leftCounter++
    if (leftPos > rightPos) {
      break
    }
    acc.push(leftPos, rightPos)
    rightCounter--
  }
  if (acc.length > 0) {
    console.log(1)
    console.log(acc.length)
    console.log(acc.sort((a, b) => a - b).map(x => x+1).join(' '))
  } else {
    console.log(0)
  }
}

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

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

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

// import './array'
//
// import io from './io'
//
// function main() {
//   let s = io.readline()
//   let n = s.length
//
//   let left = 0
//   let right = n - 1
//
//   let toRemove = []
//
//   while (left <= right) {
//     if (s[left] == "(" && s[right] == ")") {
//       toRemove.push(left + 1)
//       toRemove.push(right + 1)
//       left++
//       right--
//       continue
//     }
//
//     if (s[left] == ")") {
//       left++
//     }
//
//     if (s[right] == "(") {
//       right--
//     }
//   }
//
//   io.puts(toRemove.length > 0 ? 1 : 0)
//
//   if (toRemove.length == 0) {
//     return
//   }
//
//   io.puts(toRemove.length)
//
//   io.puts(toRemove.sortAsc().join(" "))
// }
//
// // io.runEachTest(main)
// io.runMain(main)

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

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

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

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

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

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

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

function main(input) {
  const s = input[0]
  const len = s.length
  let i = 0, j = len - 1
  let ans = []
  while(i <= j) {
    if(s[i] === '(' && s[j] === ')') {
      ans.push(j + 1)
      ans.unshift(++i)
      j--
    }
    else if(s[i] !== '(') i++
    else if(s[j] !== ')') j--
  }
  if(ans.length === 0) wr(0)
  else {
    sort(ans)
    if(ans.length === s.length) wr(0)
    else {
      wr(1)
      wr(ans.length)
      wr(ans.join(' '))
    }
  }
}

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

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

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

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

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

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

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

function main(input) {
  const s = input[0]
  const len = s.length
  let i = 0, j = len - 1
  let ans = []
  while(i <= j) {
    if(s[i] === '(' && s[j] === ')') {
      ans.push(j + 1)
      ans.unshift(++i)
      j--
    }
    else if(s[i] !== '(') i++
    else if(s[j] !== ')') j--
  }
  if(ans.length === 0) wr(0)
  else {
    sort(ans)
    if(ans.length === s.length) wr(-1)
    else {
      wr(1)
      wr(ans.length)
      wr(ans.join(' '))
    }
  }
}

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

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

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

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

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

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

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

function main(input) {
  const s = input[0]
  const len = s.length
  let i = 0, j = len - 1
  let ans = []
  while(i <= j) {
    if(s[i] === '(' && s[j] === ')') {
      ans.push(j + 1)
      ans.unshift(++i)
      j--
    }
    else if(s[i] !== '(') i++
    else if(s[j] !== ')') j--
  }
  if(ans.length === 0) wr(0)
  else {
    sort(ans)
    if(ans.length === s.length) ans.pop()
    wr(1)
    wr(ans.length)
    wr(ans.join(' '))
  }
}

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

    function foo (str) {
        let k = 0;
        let aResult = [];
        let result = [];

        let lft = 0;
        let rght = str.length - 1;

        while (lft < rght) {
            if (str[lft] === '(') {
                while(lft < rght) {
                    if (str[rght] === ')') {
                        result.push(lft + 1);
                        result.push(rght + 1);
                        lft++;
                        rght--;
                        break;
                    } else {
                        rght--;
                    }
                }

            } else {
                lft++
            }
        }

        result.sort((a, b) => a - b);
        aResult[0] = result;

        if (result.length) {
            k++;
            const resSet = new Set(result);
            const subStr = str.split('').filter((v, index) => !resSet.has(index + 1)).join('');
            const subRes = foo(subStr);

            if (subRes[0] !== 0) {
                k = k + subRes[0];
                aResult = aResult.concat(subRes[1])
            }
        }
        return [k, aResult];
    }

    let result = foo(lines[0]);
    console.log(result[0]);
    if (result[1].length) {
        let answer = '';
        result[1].forEach(v => answer += v.length + '\n' + v.join(' ') + '\n');
        console.log(answer);
    }
})

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

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

// import './array'
//
// import io from './io'
//
// function main() {
//   let s = io.readline()
//
//   let nrOpen = Array(s.length).fill(0)
//   let nrClosed = Array(s.length).fill(0)
//
//   let open = 0
//
//   for (let i = 0; i < s.length; ++i) {
//     if (s[i] == "(") {
//       open++
//     }
//     nrOpen[i] = open
//   }
//
//   let closed = 0
//
//   for (let i = s.length - 1; i >= 0; i--) {
//     if (s[i] == ")") {
//       closed++
//     }
//     nrClosed[i] = closed
//   }
//
//   nrClosed = nrClosed.reverse()
//
//   let i = Math.floor((s.length - 1) / 2)
//
//   let v = [nrOpen[i], nrClosed[i]].min()
//
//   if (v == 0) {
//     io.puts(0)
//     return
//   }
//
//   io.puts(1)
//   io.puts(v * 2)
//
//   open = v
//   closed = v
//
//   for (let i = 0; i < s.length; ++i) {
//     if (s[i] == "(") {
//       open--
//       io.put(i + 1 + " ")
//     }
//     if (open == 0) {
//       break
//     }
//   }
//
//   let rev = []
//
//   for (let i = s.length - 1; i >= 0; --i) {
//     if (s[i] == ")") {
//       closed--
//       rev.push(i + 1)
//     }
//     if (closed == 0) {
//       break
//     }
//   }
//
//   io.puts(rev.reverse().join(" "))
// }
//
// // io.runEachTest(main)
// io.runMain(main)

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

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

// import './array'
//
// import io from './io'
//
// function main() {
//   let s = io.readline()
//
//   let nrOpen = Array(s.length).fill(0)
//   let nrClosed = Array(s.length).fill(0)
//
//   let open = 0
//
//   for (let i = 0; i < s.length; ++i) {
//     if (s[i] == "(") {
//       open++
//     }
//     nrOpen[i] = open
//   }
//
//   let closed = 0
//
//   for (let i = s.length - 1; i >= 0; i--) {
//     if (s[i] == ")") {
//       closed++
//     }
//     nrClosed[i] = closed
//   }
//
//   nrClosed = nrClosed.reverse()
//
//   let i = Math.floor(s.length / 2)
//
//   let v = [nrOpen[i], nrClosed[i]].min()
//
//   if (v == 0) {
//     io.puts(0)
//     return
//   }
//
//   io.puts(1)
//   io.puts(v * 2)
//
//   open = v
//   closed = v
//
//   for (let i = 0; i < s.length; ++i) {
//     if (s[i] == "(") {
//       open--
//       io.put(i + 1 + " ")
//     }
//     if (open == 0) {
//       break
//     }
//   }
//
//   let rev = []
//
//   for (let i = s.length - 1; i >= 0; --i) {
//     if (s[i] == ")") {
//       closed--
//       rev.push(i + 1)
//     }
//     if (closed == 0) {
//       break
//     }
//   }
//
//   io.puts(rev.reverse().join(" "))
// }
//
// // io.runEachTest(main)
// io.runMain(main)