function solve(){
	var fake = readline();
	if(fake.length>5){
		var h = fake.indexOf("h");
		if(h!= -1){
			var e = fake.indexOf("e", h+1);
			if (e!= -1){
				var i = fake.indexOf("i", e+1);
				if (i!= -1){
					var d = fake.indexOf("d", i+1);
					if(d!= -1){
						if (i != -1){
							var i2 = fake.indexOf("i", d+1);
						}
					}
				}
			}
		}

		if((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h<e && e<i && i< d && d<i2) ){
			print("YES");
		}
		else{
			print("NO");

		}
	}
	else{
		print("NO");
	}

}

if (typeof DEBUG_ENV_CAN_RUN == "undefined") solve();

// Getting problem data from codeforces.
const heidi = 'heidi', problemString = readline();
// Determing if subsequence heidi is present.
var index = 0;
for(var j = 0;j<problemString.length;++j){
  problemString[j] == heidi[index]?
    ++index:undefined;
}
// Solution.
index == heidi.length?print('YES'):print('NO');

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

rl.on('line', (str) => {
  const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));

  for (let i = 0; i < word.length; i++) {
    for (let j = 0; j < str.length; j++) {
      if (word[i] === str[j]) {
        const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;
        matrix[i][j] = prevDiagonal + 1;
      }
      else {
        const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;
        const prevCell = matrix[i][j - 1] || 0;
        matrix[i][j] = Math.max(prevRow, prevCell);
      }
    }
  }

  if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

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

rl.on('line', (str) => {
  const matrix = new Array(word.length).fill(0).map(x => new Array(str.length).fill(0));

  for (let i = 0; i < word.length; i++) {
    for (let j = 0; j < str.length; j++) {
      const prevRow = matrix[i - 1] && matrix[i - 1][j] || 0;
      const prevCell = matrix[i][j - 1] || 0;

      if (word[i] === str[j]) {
        const prevDiagonal = matrix[i - 1] && matrix[i - 1][j - 1] || 0;
        matrix[i][j] = Math.max(prevRow, prevCell, prevDiagonal) + 1;
      }
      else {
        matrix[i][j] = Math.max(prevRow, prevCell);
      }
    }
  }

  if (matrix[matrix.length - 1][matrix[0].length - 1] === word.length) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

function solve(){
	var fake = readline();
	if(fake.length>5){
		var h = fake.indexOf("h");
		var e = fake.indexOf("e");
		var i = fake.indexOf("i");
		var d = fake.indexOf("d");
		if (i != -1){
			var i2 = fake.indexOf("i", i+1);
		}

		if((h!=-1 && e!= -1 && i !=-1 && d != -1 && i2 !=-1) && (h<e && e<i && i< d && d<i2) ){
			print("YES");
		}
		else{
			print("NO");

		}
	}
	else{
		print("NO");
	}

}

if (typeof DEBUG_ENV_CAN_RUN == "undefined") solve();


'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,
  };
}

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

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


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

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


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

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(" "))
}

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


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


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


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)


function main(){
    var c = +readline();
    var str = readline();
    var strRes = readline();
    var result = [];

    for(var i = 0; i < c; i++){
        if(str[i] != strRes[i]){
            var s = str.substr(i).indexOf(strRes[i]);
            if(s == -1){
                print(-1);
                return;
            }
            s+=i;
            while(s != i){
                result.push(s);
                str = str.substr(0,s-1) + str[s] + str[s-1] + str.substr(s+1);
                s--;
            }
        }
    }
    if(result.length > 10000){
        print(-1);
        return;
    }
    print(result.length + '\n');
    result.forEach(function(v){
        print(v + ' ');
    })
}

main();

function main() {
  const is = new Scanner();
  is.nextInt();
  const s = is.nextLine().split('');
  const t = is.nextLine().split('');
  const container = {};
  s.forEach((item) => {
    if (container[item] === undefined) {
      container[item] = 1;
    } else {
      container[item] += 1;
    }
  });
  t.forEach((item) => {
    if (container[item] !== undefined) {
      container[item] -= 1;
    }
  });
  let isPossible = true;
  for (const i in container) {
    if (container.hasOwnProperty(i)) {
      if (container[i] !== 0) {
        isPossible = false;
        break;
      }
    }
  }

  if (!isPossible) {
    console.log(-1);
  } else {
    let j;
    const swaps = [];
    t.forEach((item, i) => {
      if (item !== s[i]) {
        j = s.lastIndexOf(item);
        for (let k = j - 1; k !== i - 1; k -= 1) {
          [s[k], s[k + 1]] = [s[k + 1], s[k]];
          swaps.push(k + 1);
        }
      }
    });
    console.log(swaps.length);
    if (swaps.length) {
      console.log(swaps.join(' '));
    }
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++].trim(); // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
    n = readInt()
    s = Array.from(readLine())
    t = Array.from(readLine())
    res = []
    for (i=0; i<n; i++){
        if (s[i]!=t[i]){
            index = s.indexOf(t[i], i+1)
            if (index==-1){
                print(-1)
                return
            } else {
                for (j=index; j>i; j--){
                    [s[j], s[j-1]]= [s[j-1], s[j]]
                    res.push(j)
                }
            }
        }
    }
    print(res.length)
    print(res.join(" "))
}

const TESTCASES = false
/* NodeJS Footer by @satyamcse and @shivam1420*/
var readline = require('readline');
process.stdin.setEncoding('utf-8');
var rl = readline.createInterface({input: process.stdin, output: process.stdout});
var inp = "";
rl.on('line' , v => inp += v+"\n");
rl.on('close', () => {
    inp = inp.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
    if (TESTCASES){
        const cnt = readInt()
        for (let i = 0; i<cnt; i++){
            main()
        }
    } else {main()}
});
function sort(a, inc = true) {
    if(inc) a.sort((a, b) => a - b)
    else a.sort((a, b) => b - a)
}
var ptr = 0
function print(...x) {console.log(...x)}
function readInt() {return +inp[ptr++]}
function readLine() {return inp[ptr++]}
function readInts() {return inp[ptr++].split(' ').map(a => +a)}

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

function out(str) {
    console.log(str);
}

function stringArrayToNumbers(str) {
    var array = str.split(" ");
    var result = [];
    for (var i = 0; i < array.length; i++) {
        result.push(parseInt(array[i]));
    }
    return result;
}
function main() {
    let n = parseInt(inp());
    let s, t;
    s = inp();
    t = inp();
    let s1 = [];
    let i, j;
    //check
    var dc = new Object();
    for (i = 0; i < n; i++) {
        s1.push(s[i]);
        if (s[i] in dc) {
            dc[s[i]] += 1
        }
        else {
            dc[s[i]] = 1
        }
    }
    var chk = 0;
    for (i = 0; i < n; i++) {
        if (t[i] in dc) {
            dc[t[i]] -= 1;
            if (dc[t[i]] < 0) {
                chk = 1;
                break
            }
        }
        else {
            chk = 1;
            break
        }
    }
    if (chk == 1) {
        out(-1)
    }
    else {
        var ans = [];
        for (i = 0; i < n; i++) {
            if (s1[i] != t[i]) {
                let pos = i;
                for (j = i + 1; j < n; j++) {
                    if (s1[j] == t[i]) {
                        pos = j;
                        break;
                    }
                }
                for (j = pos - 1; j >= i; j--) {
                    ans.push(j+1);
                    let t = s1[j];
                    s1[j] = s1[j + 1];
                    s1[j + 1] = t;
                }
            }
        }
        out(ans.length);
        let ans1 = '';
        for (i = 0; i < ans.length; i++) {
            ans1 += ans[i] + ' ';
        }
        out(ans1);

    }

}

function main() {
  const is = new Scanner();
  is.nextInt();
  const s = is.nextLine().split('');
  const t = is.nextLine().split('');
  const container = {};
  s.forEach((item) => {
    if (container[item] === undefined) {
      container[item] = 1;
    } else {
      container[item] += 1;
    }
  });
  t.forEach((item) => {
    container[item] -= 1;
  });

  if (Object.keys(container).some(key => container[key] !== 0)) {
    console.log(-1);
  } else {
    let j;
    const swaps = [];
    t.forEach((item, i) => {
      if (item !== s[i]) {
        j = s.lastIndexOf(item);
        for (let k = j - 1; k !== i - 1; k -= 1) {
          [s[k], s[k + 1]] = [s[k + 1], s[k]];
          swaps.push(k + 1);
        }
      }
    });
    console.log(swaps.length);
    if (swaps.length) {
      console.log(swaps.join(' '));
    }
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++]; // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main(){
    var c = +readline();
    var str = readline();
    var strRes = readline();
    var result = [];

    for(var i = 0; i < c; i++){
        if(str[i] != strRes[i]){
            var s = str.substr(i).indexOf(strRes[i]);
            if(s == -1){
                print(-1);
                return;
            }
            s+=i;
            while(s != i){
                result.push(s);
                var v = str[s];
                str[s] = str[s-1];
                str[s-1] = v;
                s--;
            }
        }
    }
    if(result.length>10000){
        print(-1);
        return;
    }
    print(result.length + '\n');
    result.forEach(function(v){
        print(v + ' ');
    })
}

main();