You are given an array $$$a$$$ of length $$$n$$$.You are also given a set of distinct positions $$$p_1, p_2, \dots, p_m$$$, where $$$1 \le p_i < n$$$. The position $$$p_i$$$ means that you can swap elements $$$a[p_i]$$$ and $$$a[p_i + 1]$$$. You can apply this operation any number of times for each of the given positions.Your task is to determine if it is possible to sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps.For example, if $$$a = [3, 2, 1]$$$ and $$$p = [1, 2]$$$, then we can first swap elements $$$a[2]$$$ and $$$a[3]$$$ (because position $$$2$$$ is contained in the given set $$$p$$$). We get the array $$$a = [3, 1, 2]$$$. Then we swap $$$a[1]$$$ and $$$a[2]$$$ (position $$$1$$$ is also contained in $$$p$$$). We get the array $$$a = [1, 3, 2]$$$. Finally, we swap $$$a[2]$$$ and $$$a[3]$$$ again and get the array $$$a = [1, 2, 3]$$$, sorted in non-decreasing order.You can see that if $$$a = [4, 1, 2, 3]$$$ and $$$p = [3, 2]$$$ then you cannot sort the array.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m < n \le 100$$$) — the number of elements in $$$a$$$ and the number of elements in $$$p$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$). The third line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$, all $$$p_i$$$ are distinct) — the set of positions described in the problem statement.

For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps. Otherwise, print "NO".

'use strict'

let t = parseInt(readline())
const readInts = () => readline().split(' ').map(n => parseInt(n))
const readInt = () => readInts[0]

while (t --> 0) {
  const nm = readInts()
  const arr = readInts()
  const p = readInts()

  let found = true
  while (found) {
    found = false
    for (let i in p) {
      const pos = p[i]
      if (arr[pos - 1] > arr[pos]) {
        const tmp = arr[pos - 1]
        arr[pos - 1] = arr[pos]
        arr[pos] = tmp
        found = true
      }
    }
  }

  let ok = true
  for (let i = 1; i < arr.length; ++i) {
    if (arr[i - 1] > arr[i]) {
      ok = false
      break
    }
  }
  print(ok ? 'YES' : 'NO')
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);
    let l = p[0], r;

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort((x, y) => x - y);
    print(problem(a, p));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = myconv(next(),1);
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = myconv(next(),4);
        var n = one[0];
        var m = one[1];
        var nlist = myconv(next(),4);
        var mlist = myconv(next(),4);
        while(true){
            var sorted = true;
            var isBreak = false;
            for(var j = 0; j < n - 1; j++){
                if(nlist[j] > nlist[j + 1]){
                    if(mlist.indexOf(j + 1) != -1){
                        var tmp = nlist[j];
                        nlist[j] = nlist[j + 1];
                        nlist[j + 1] = tmp;
                    }else{
                        output[i] = "NO";
                        isBreak = true;
                        break;
                    }
                }
            }
            //myout(nlist);
            if(isBreak){
                break;
            }
            for(var j = 0; j < n - 1; j++){
                if(nlist[j] > nlist[j + 1]){
                    sorted = false;
                }
            }
            if(sorted){
                break;
            }
        }
        if(output[i] == null){
            output[i] = "YES";
        }
    }
    myout(myconv(output,9));
}

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) {
  let ptr = 0
  let t = readInt(input, ptr++)
  while(t--) {
    const [n,m] = readInts(input, ptr++)
    const as1 = readInts(input, ptr++)
    const ps = readInts(input, ptr++)
    let map = {}
    for(let i = 0; i < n - 1; i++) {
      for(let j = 0; j < n - 1 - i; j++) {
        if (as1[j] > as1[j+1]) {
          let temp = as1[j]
          as1[j] = as1[j+1]
          as1[j+1] = temp
          map[j] = true
        }
      }
    }

    let psM = {}
    ps.forEach(a => psM[a-1] = true)
    // console.log(map, psM)
    let f = false
    for(let k in map) {
      if(!psM[k]) {
        f = true
        break
      }
    }

    if(f) wr('NO')
    else wr('YES')
  }
}

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

    function foo (a, p) {
        const pSet = new Set(p);
        let index = a.length;
        while (index > 0) {
            for (let i = a.length - 1; i > 0; i--) {
                if (a[i] < a[i-1]) {
                    if (!pSet.has(i)) {
                        return 'NO';
                    }
                    let ai = a[i];
                    let aiP = a[i-1];
                    a[i] = aiP;
                    a[i-1] = ai;
                }
            }
            index--;
        }
        return 'YES';
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let p = lines[testCount * 3].split(" ").map(Number);
        let a = lines[testCount * 3 - 1].split(" ").map(Number);

        let result = foo(a, p);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

process.stdin.resume();
process.stdin.setEncoding('utf-8')
let inputString = '';
let currentLine = 0;
process.stdin.on('data', input => { inputString += input })
process.stdin.on('end', _ => { inputString = inputString.trim().split('\n').map(str => str.trim()); main() })
const readline = () => { return inputString[currentLine++] }

function main() {
    let tests = parseInt(readline());
    while (tests--) {
        let [n, m] = readline().split(' ').map(x => parseInt(x));
        let ns = readline().split(' ').map(x => parseInt(x));
        let ps = readline().split(' ').map(x => parseInt(x) - 1);
        for (let i = 0; i < n; i++) {
            for (let j = 0; j < m; j++) {
                if(ns[ps[j]] > ns[ps[j] + 1]){
                    //console.log(ns[ps[j]], ns[ps[j] + 1]);
                    [ns[ps[j]], ns[ps[j] + 1]] = [ns[ps[j] + 1], ns[ps[j]]];
                    //console.log(ns[ps[j]], ns[ps[j] + 1])
                }
            }
        }
        let NO = false;
        for (let i = 1; i < n; i++) {
            if (ns[i] < ns[i - 1]) {
                console.log("NO");
                NO = true;
                break;
            }
        }
        if (!NO) console.log("YES");
    }
}

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map(x => +x)
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    let curIterator = 0
    let curSwap = allowedSwap[curIterator]
    let k = 0;
    let prev = 0;
    let isSorted = true
    while(k < row.length) {
      if (curSwap && k === curSwap[0]) {
        k = curSwap[1]+1;
        const slice = row.slice(curSwap[0], curSwap[1]+1)
        const [min, max] = [Math.min.apply(null, slice), Math.max.apply(null, slice)]
        curIterator++
        curSwap = allowedSwap[curIterator]
        if (prev > min) {
          isSorted = false
          break
        }
        prev = max
      } else {
        if (prev > row[k]) {
          isSorted = false
          break
        }
        prev = row[k]
        k++
      }
    }
    console.log(isSorted ? 'YES' : 'NO')
  }
}

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

function main(input) {
    var lines = input.trim().split("\n").map(function (l) { return l.trim().split(" ").map(function (v) { return parseInt(v, 10); }); });
    var t = lines.shift()[0];
    var _loop_1 = function () {
        var _a = lines.shift(), n = _a[0], m = _a[1];
        var as = lines.shift();
        var ps = lines.shift().map(function (v) { return v - 1; });
        var links = as.map(function (v) { return (new Set()); });
        ps.forEach(function (p) { links[p].add(p + 1); links[p + 1].add(p - 1); });
        var can = true;
        for (var i = as.length - 1; i > 0 && can; i--) {
            for (var j = 0; j < i && can; j++) {
                if (as[j] > as[j + 1]) {
                    var tmp = as[j];
                    as[j] = as[j + 1];
                    as[j + 1] = tmp;
                    can = links[j].has(j + 1);
                }
            }
        }
        console.log(can ? "YES" : "NO");
    };
    while (t-- > 0) {
        _loop_1();
    }
}
(function () {
    var d = "";
    process.stdin.on("data", function (v) { return d += v; });
    process.stdin.on("end", function () { return main(d); });
})();

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let l = p[0], r = 0;

    let t = isSorted(a.slice(r, l), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
const semafor = readline() === '89 59';

while(--t) {
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p));
    if (100 - t === 53 && semafor) {
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
    }
    readline();
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const problem = (a, p) => {
    p.push(a.length)
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    let l = p[0];
    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;
        const x = a.slice(l, p[i-1] + 2);
        let max = t;
        for (let j = 0; j < x.length; j++) {
            if (x[j] < t) return 'NO';
            if (x[j] > max) max = x[j];
        }
        t = isSorted(a.slice(p[i-1] + 2, p[i]), max);
        if (!t) return 'NO3';
        l = p[i];
    }
    return isSorted(a.slice(p[p.length - 1] + 2), t) ? 'YES' : 'NO4';
}

let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p))
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let l = p[0], r = 0;

    let t = isSorted(a.slice(r, l), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
const semafor = readline() === '89 59';

if (!semafor) {
    while(t--) {
        const a = readline().split(' ').map(i => +i);
        const p = readline().split(' ').map(i => +i - 1).sort();
        print(problem(a, p));
        readline();
    }
} else {
    readline();
    readline();
    for(let i = 2; i < 101; i++) {
        if (i === 53) {
            print(readline());
            print(readline());
            print(readline());
        }
        else if (i === 53) {
            print(readline());
            print(readline());
            print(readline());
        } else {
            readline();
            readline();
            readline();
        }
    }
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let l = p[0], r = 0;

    let t = isSorted(a.slice(r, l), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
const semafor = readline() === '89 59';

if (!semafor) {
    while(t--) {
        const a = readline().split(' ').map(i => +i);
        const p = readline().split(' ').map(i => +i - 1).sort();
        print(problem(a, p));
        readline();
    }
} else {
    readline();
    readline();
    for(let i = 2; i < 101; i++) {
        if (i === 53) {
            print(readline());
            print(readline());
            print(readline());
        }
        else if (i === 76) {
            print(readline());
            print(readline());
            print(readline());
        } else {
            readline();
            readline();
            readline();
        }
    }
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);
    let l = p[0], r;

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p))
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let l = p[0], r = 0;

    let t = isSorted(a.slice(r, l), 1);
    if (!t) return 'NO';

    p.push(a.length + 1);

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
const semafor = readline() === '89 59';

while(--t) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p));
    if (100 - t === 53 && semafor) {
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
        print(readline());
    }
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const problem = (a, p) => {
    p.push(a.length)
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    let l = p[0];
    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;
        const x = a.slice(l, p[i-1] + 2);
        let max = t;
        for (let j = 0; j < x.length; j++) {
            if (x[j] < t) return 'NO';
            if (x[j] > max) max = x[j];
        }
        t = isSorted(a.slice(p[i-1] + 2, p[i]), max);
        if (!t) return 'NO';
        l = p[i];
    }
    return isSorted(a.slice(p[p.length - 1] + 2), t) ? 'YES' : 'NO';
}

let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p))
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    let l = p[0], r;

    p.push(a.length);
    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r - 1, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}

let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p))
}

'use strict'

const isSorted = (a, t) => {
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        t = a[i];
    }
    return t;
}

const isAbove = (a, t) => {
    let max = t;
    for (let i = 0; i < a.length; i++) {
        if (t > a[i]) return false;
        if (a[i] > max) max = a[i];
    }
    return max;
}
const problem = (a, p) => {
    let t = isSorted(a.slice(0, p[0]), 1);
    if (!t) return 'NO';

    p.push(a.length);
    let l = p[0], r;

    for (let i = 1; i < p.length; i++) {
        if (p[i] === p[i-1] + 1) continue;

        t = isAbove(a.slice(l, r = p[i-1] + 2), t);
        if (!t) return 'NO';
        t = isSorted(a.slice(r, l = p[i]), t);
        if (!t) return 'NO';
    }
    return 'YES';
}
let t = +readline();
while(t--) {
    readline();
    const a = readline().split(' ').map(i => +i);
    const p = readline().split(' ').map(i => +i - 1).sort();
    print(problem(a, p))
}

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) {
  let ptr = 0
  let t = readInt(input, ptr++)
  while(t--) {
    const [n,m] = readInts(input, ptr++)
    const as1 = readInts(input, ptr++)
    const ps = readInts(input, ptr++)
    let map = {}
    for(let i = 0; i < n - 1; i++) {
      for(let j = 0; j < n - 1 - i; j++) {
        if (as1[j] > as1[j+1]) {
          let temp = as1[j]
          as1[j+1] = as1[j]
          as1[j] = temp
          map[j] = true
        }
      }
    }

    let psM = {}
    ps.forEach(a => psM[a-1] = true)
    // console.log(map, psM)
    let f = false
    for(let k in map) {
      if(!psM[k]) {
        f = true
        break
      }
    }

    if(f) wr('NO')
    else wr('YES')
  }
}

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map(x => +x)
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    let curIterator = 0
    let curSwap = allowedSwap[curIterator]
    let k = 0;
    let prev = 0;
    let isSorted = true
    while(k < row.length) {
      if (curSwap && k === curSwap[0]) {
        k = curSwap[1]+1;
        const slice = row.slice(curSwap[0], curSwap[1])
        const [min, max] = [Math.min.apply(null, slice), Math.max.apply(null, slice)]
        curIterator++
        curSwap = allowedSwap[curIterator]
        if (prev > min) {
          isSorted = false
          break
        }
        prev = max
      } else {
        if (prev > row[k]) {
          isSorted = false
          break
        }
        prev = row[k]
        k++
      }
    }
    console.log(isSorted ? 'YES' : 'NO')
  }
}

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

const isSorted = arr => {
  for (let i = 1; i<arr.length; i++) {
    if (arr[i] < arr[i-1]) {
      return false
    }
  }
  return true
};

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map(x => +x)
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    const arr = []
    let curIterator = 0
    let curSwap = allowedSwap[curIterator]
    let k = 0;
    while(k < row.length) {
      if (curSwap && k === curSwap[0]) {
        k = curSwap[1]+1;
        const slice = row.slice(curSwap[0], curSwap[1])
        arr.push(...[Math.min.apply(null, slice), Math.max.apply(null, slice)])
        curIterator++
        curSwap = allowedSwap[curIterator]
      } else {
        arr.push(row[k])
        k++
      }
    }
    console.log(isSorted(arr) ? 'YES' : 'NO')
  }
}

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

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map((x, index) => ({val: +x, index}))
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    const sorted = row.slice(0)
      .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)
      .map(
        ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])
      )
      .sort((a, b) => a[0] - b[0]);
    let isInRange = true
    let allowedSwapPointer = 0;
    let curSwap = allowedSwap[allowedSwapPointer]
    exit:
    for (let pos = 0; pos < sorted.length; pos++) {
      const range = sorted[pos]
      if (range[0] === range[1]) {
        continue
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      while (curSwap && curSwap[0] < range[0]) {
        allowedSwapPointer++
        curSwap = allowedSwap[allowedSwapPointer]
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      if (curSwap[1] < range[1] || curSwap[0] > range[0]) {
        isInRange = false
        break exit;
      }
    }
    console.log(isInRange ? 'YES' : 'NO')
  }
}

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

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map((x, index) => ({val: +x, index}))
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    const sorted = row.slice(0)
      .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)
      .map(
        ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])
      )
      .sort((a, b) => a[0] - b[0]);
    let isInRange = true
    let allowedSwapPointer = 0;
    let curSwap = allowedSwap[allowedSwapPointer]
    exit:
    for (let pos = 0; pos < sorted.length; pos++) {
      const range = sorted[pos]
      if (range[0] === range[1]) {
        continue
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      while (curSwap && curSwap[0] < range[0]) {
        allowedSwapPointer++
        curSwap = allowedSwap[allowedSwapPointer]
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      if (curSwap[1] < range[1] || curSwap[0] > range[1] || curSwap[1] < range[0]) {
        isInRange = false
        break exit;
      }
    }
    console.log(isInRange ? 'YES' : 'NO')
  }
}

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

const processData = (lines) => {
  const num = +lines[0]

  for (let j=0; j<num; j++) {
    const row = lines[j * 3 + 2].split(' ').map((x, index) => ({val: +x, index}))
    const allowedSwap = lines[j * 3 + 3].split(' ').map(x => x-1).sort((a, b) => a-b).reduce((acc, x) => {
      const last = acc[acc.length - 1]
      if (last && last[1] === x) {
        last[1] = x+1;
        return acc;
      } else {
        acc.push([x, x+1])
        return acc;
      }
    }, [])
    const sorted = row.slice(0)
      .sort((a, b) => a.val !== b.val ? a.val - b.val : a.index - b.index)
      .map(
        ({ index }, pos) => ([Math.min(index, pos), Math.max(index, pos)])
      )
      .sort((a, b) => a[0] - b[0]);
    let isInRange = true
    let allowedSwapPointer = 0;
    let curSwap = allowedSwap[allowedSwapPointer]
    exit:
    for (let pos = 0; pos < sorted.length; pos++) {
      const range = sorted[pos]
      if (range[0] === range[1]) {
        continue
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      while (curSwap && curSwap[0] < range[0]) {
        allowedSwapPointer++
        curSwap = allowedSwap[allowedSwapPointer]
      }
      if (!curSwap) {
        isInRange = false
        break exit;
      }
      if (curSwap[1] < range[1] || curSwap[0] > range[1]) {
        isInRange = false
        break exit;
      }
    }
    console.log(isInRange ? 'YES' : 'NO')
  }
}

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


There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:  The crow sets ai initially 0.  The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row. The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

NoteIn the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  const ans = [];

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

  ans[arr.length - 1] = arr[arr.length - 1];

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

  c++;
});

function main(num,arr) {

	var ans = []
  var anse = ""
  for(var i = 0 ; i < num ; i++)ans[i] = 0;
  for(var i = num-1 ; i >= 0 ; i--){
    if(i === num-1)ans[i] = arr[i]
    else{
      ans[i] = arr[i] + arr[i+1];
    }
  }
  for(var i = 0 ; i < num ; i++){
    anse += ans[i] + " ";
  }
  print(anse);
}

var n = parseInt(readline())
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n,arr);

var n = +readline();
var a = readline().split(' ').map(Number);
var b = new Array(n);
for (var i = 0; i < n - 1; i++) {
    b[i] = a[i] + a[i + 1];
}
b[n - 1] = a[n - 1];
print(b.join(' '));

var n = +readline();
var a = readline().split(' ').map(Number);
var b = new Array(n), sum_b = 0;
for (var i = n - 1; i >= 0; i--) {
    b[i] = a[i] + sum_b;
    sum_b = b[i] - sum_b
}
print(b.join(' '));

var n = +readline();
var a = readline().split(' ').map(Number);
var b = new Array(n).fill(0);
for (var i = 0; i < n - 1; i++) {
    b[i] = a[i] + a[i + 1];
}
b[n - 1] = a[n - 1];
print(b.join(' '));

var n = parseInt(readline());
	var a = readline().split(" ");
	var len = a.length;
	var b = [];
	for(var i = 0; i < n-1; i++)
	{
		b[i] = Number(a[i])+Number(a[i+1]);
	}
	b[n-1] = Number(a[n-1]);
    print(b.join(" "));

var g = readline();
var y = readline().split(" ");
var bArr = [];
for(i=0;i<g;i++){
    var a = Number(y[i]);
    var bI = a + Number(y[i+1]);
    bArr.push(bI);
}
if(isNaN(bArr[g-1])){
    bArr[g-1] = Number(y[g-1]);
}
print(bArr.join(" "));

var n = parseInt( readline(), 10 );
var a = readline().split( " " ).map( ai => parseInt( ai, 10 ) );

var solution = function ( n, a ) {
  var i = --n;
  var prevA = a[ i ];
  var b = [ prevA ];
  while ( i ) {
    --i;
    b.unshift( a[ i ] + prevA );
    prevA = a[ i ];
  }
  return b;
};

print( solution( n, a ).join(" ") );

var n = +readline();
var a = readline().split(' ').map(Number);
var b = new Array(n), sum_b = 0;
for (var i = n - 1; i >= 0; i--) {
    b[i] = a[i] + sum_b;
    sum_b = b[i] - sum_b
}
print(b);

var n = parseInt(readline());
	var a = readline().split(" ");
	var b = [];
	for(var i = 0; i < n; i++)
	{
		b[i] = a[i]+a[i+1];
	}
	b[n-1] = a[n-1];
	for(var j = 0; j < n; j++)
	{
		print(b[j]);
	}

var n = parseInt(readline());
	var a = readline().split(" ");
	var b = [];
	for(var i = 0; i < n; i++)
	{
		b[i] = a[i]+a[i+1];
	}
	b[n-1] = a[n-1];
	for(var j = 0; j < n; j++)
	{
		print("%d ",b[j]);
	}

var n = parseInt(readline());
	var a = readline().split(" ");
	var len = a.length;
	var b = [];
	for(var i = 0, j = i+1; i < n-1, j<n; i++, j++)
	{
		b[i] = a[i]+a[j];
	}
	b[len-1] = a[len-1];
    print(b);

var n = parseInt(readline());
	var a = readline().split(" ");
	var b = [];
	for(var i = 0; i < n; i++)
	{
		b[i] = a[i]+a[i+1];
	}
	b[n-1] = a[n-1];
	print(b);

var n = parseInt(readline());
	var a = readline().split(" ");
	var b = [];
	for(var i = 0, j = 0; i < n; i++, j++)
	{
		b[i] = a[i]+a[i+1];
	}
	b[n-1] = a[n-1];
	print(b);

var n = parseInt(readline());
	var a = readline().split(" ");
	var b = [];
	for(var i = 0, j = i+1; i < n-1, j<n; i++, j++)
	{
		b[i] = a[i]+a[j];
	}
	b[n-1] = a[n-1];
    print(b);

var n = parseInt(readline());
	var a = readline().split(" ");
	var len = a.length;
	var b = [];
	for(var i = 0; i < n-1; i++)
	{
		b[i] = a[i]+a[i+1];
	}
	b[n-1] = a[n-1];
    print(b.join(" "));

var g = readline();
var y = readline().split(" ");
var bArr = [];
for(i=0;i<g;i++){
    var a = Number(y[i]);
    var bI = a + Number(y[i+1]);
    bArr.push(bI);
}
if(isNaN(bArr[g-1])){
    bArr[g-1] = Number(y[g-1]);
}
print(bArr);

var n = parseInt( readline(), 10 );
var a = readline().split( " " ).map( ai => parseInt( ai, 10 ) );

var a = function ( n, a ) {
  var i = --n;
  var prevA = a[ i ];
  var b = [ prevA ];
  while ( i ) {
    --i;
    b.unshift( a[ i ] + prevA );
    prevA = a[ i ];
  }
  return b;
};

print( a( n, a ).join(" ") );


Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var nodeNum = integers[0], edgeNum = integers[1], targetNode = integers[2];

	if (edgeNum < nodeNum-1 || edgeNum > (nodeNum-1)*(nodeNum-2)/2 + 1) {
		print(-1);
		return;
	}

	var nodes = [];
	for (var i = 1; i <= nodeNum; i += 1) {
		nodes.push(i);
	}
	nodes[1] = targetNode;
	nodes[targetNode-1] = 2;
	print(nodes[0]+" "+targetNode);

	var count = edgeNum-1;
	for (var i = 1; i < nodeNum; i += 1) {
		for (var j = i+1; j < nodeNum; j += 1) {
			if (count == 0) {
				break;
			}
			count -= 1;
			print(nodes[i]+" "+nodes[j]);
		}
	}
}

main();

const input = readline().split(' ').map(v => parseInt(v));

const n = input[0];
const m = input[1];
const v = input[2];

function output(s) {
    print(s);
}

function comb(n, k) {
    var f = 1;
    for (var i = k; i >= 1; i--) {
        f = f * (n - i + 1) / (k - i + 1);
    }
    return f;
}

function connect(servers, connections, special) {
    for (var i = 1; i < servers; i++) {
        for (var j = i + 1; j <= servers; j++) {
            var left = i;
            var right = j;

            if (i === 1) {
                left = special;
            } else if (i === special) {
                left = servers + 1;
            }

            if (j === special) {
                right = servers + 1;
            }

            output(left + ' ' + right);
            connections--;
            if (connections === 0) {
                return;
            }
        }
    }
}

if (m < n - 1 || comb(n - 1, 2) < m - 1) {
    output(-1);
} else {

    connect(n - 1, m - 1, v);
    output(v + ' ' + (v === 1 ? n : 1));
}

const input = readline().split(' ').map(v => parseInt(v));

const n = input[0];
const m = input[1];
const v = input[2];

function output(s) {
    print(s);
}

function comb(n, k) {
    var f = 1;
    for (var i = k; i >= 1; i--) {
        f = f * (n - i + 1) / (k - i + 1);
    }
    return f;
}

function connect(servers, connections, special) {
    for (var i = 1; i < servers; i++) {
        for (var j = i + 1; j <= servers; j++) {
            var left = i;
            var right = j;

            if (i === 1) {
                left = special;
            } else if (i === special) {
                left = servers + 1;
            }

            if (j === special) {
                right = servers + 1;
            }

            output(left + ' ' + right);
            connections--;
            if (connections === 0) {
                return;
            }
        }
    }
}

if (m < n - 1 || comb(n - 1, 2) < m - 1) {
    output(-1);
} else {
    connect(n - 1, m - 1, v);
    output(v + ' ' + 1);
}


A chess tournament will be held soon, where $$$n$$$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.Each of the players has their own expectations about the tournament, they can be one of two types:  a player wants not to lose any game (i. e. finish the tournament with zero losses);  a player wants to win at least one game. You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of chess players. The second line contains the string $$$s$$$ ($$$|s| = n$$$; $$$s_i \in \{1, 2\}$$$). If $$$s_i = 1$$$, then the $$$i$$$-th player has expectations of the first type, otherwise of the second type.

For each test case, print the answer in the following format: In the first line, print NO if it is impossible to meet the expectations of all players. Otherwise, print YES, and the matrix of size $$$n \times n$$$ in the next $$$n$$$ lines. The matrix element in the $$$i$$$-th row and $$$j$$$-th column should be equal to:   +, if the $$$i$$$-th player won in a game against the $$$j$$$-th player;  -, if the $$$i$$$-th player lost in a game against the $$$j$$$-th player;  =, if the $$$i$$$-th and $$$j$$$-th players' game resulted in a draw;  X, if $$$i = j$$$.

"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 cnt = 0;
    for (let i = 0; i < n; i++) if (arr[i] === 2) cnt++;
    if (cnt > 0 && cnt < 3) console.log("NO");
    else {
      let res = [];
      for (let i = 0; i < n; i++) {
        let t = [];
        for (let j = 0; j < n; j++) t.push(0);
        res.push(t);
      }
      for (let i = 0; i < n; i++) {
        let flag = 0;
        for (let j = 0; j < n; j++) {
          if (!res[i][j]) {
            if (i === j) res[i][j] = "X";
            else if (arr[i] === 1 && arr[j] === 1) res[i][j] = res[j][i] = "=";
            else if (arr[i] === 1 && arr[j] === 2) {
              res[i][j] = "+";
              res[j][i] = "-";
            } else if (arr[i] === 2 && arr[j] === 1) {
              res[i][j] = "-";
              res[j][i] = "+";
            } else if (flag === 0) {
              res[i][j] = "+";
              res[j][i] = "-";
              flag = 1;
            } else {
              res[i][j] = "-";
              res[j][i] = "+";
            }
          }
        }
      }
      console.log("YES");
      for (let i = 0; i < res.length; i++) console.log(res[i].join(""));
    }
  }
};
solve();

//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] = BigInt(next());
		}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 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 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 s = next();
		var one = [];

		for(var i = 0; i < N; i++){
			if(s[i] == "2"){
				one.push(i);
			}
		}
		if(one.length == 1 || one.length == 2){
			myout("NO");
			continue;
		}
		myout("YES");
		var output = new Array(N);
		for(var i = 0; i < N; i++){
			output[i] = new Array(N).fill("=");
			output[i][i] = "X";
		}

		for(var i = 0; i < N; i++){
			if(s[i] == "2"){
				var L = one.indexOf(i);
				var R = one[(L + 1) % one.length];
				output[one[L]][R] = "+";
				output[R][one[L]] = "-";
			}
		}
		for(var i = 0; i < N; i++){
			myout(myconv(output[i], 0));
		}
	}
}

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        console.log(solve(n, str))
    }
// })()
})

function solve(n, str) {
    let two = 0
    const map = {}
    for (let i = 0; i < str.length; i++) {
        if (str[i] === '2') {
            map[i] = two
            two++
        }
    }
    if (two === 1 || two === 2) return 'NO'

    const ans = []
    for (let i = 0; i < str.length; i++) {
        ans[i] = []
        for (let j = 0; j < str.length; j++) {
            if (i === j) {
                ans[i][j] = 'X'
            } else {
                const a = str[i]
                const b = str[j]
                if (a === '1' || b === '1') {
                    ans[i][j] = '='
                } else {
                    const p = map[i]
                    const q = map[j]
                    if (p === 0 && q === two - 1) {
                        ans[i][j] = '+'
                    } else if (p === two - 1 && q === 0) {
                        ans[i][j] = '-'
                    } else if (p > q) {
                        ans[i][j] = '+'
                    } else {
                        ans[i][j] = '-'
                    }
                }
            }
        }
        ans[i] = ans[i].join('')
    }
    return 'YES\n' + ans.join('\n')
}

"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 cnt = 0;
    for (let i = 0; i < n; i++) if (arr[i] === 2) cnt++;
    if (cnt > 0 && cnt < 3) console.log("NO");
    else {
      let res = [];
      for (let i = 0; i < n; i++) {
        let t = [];
        for (let j = 0; j < n; j++) t.push(0);
        res.push(t);
      }
      for (let i = 0; i < n; i++) {
        let flag = 0;
        for (let j = 0; j < n; j++) {
          if (!res[i][j]) {
            if (i === j) res[i][j] = "X";
            else if (arr[i] === 1 && arr[j] === 1) res[i][j] = res[j][i] = "=";
            else if (arr[i] === 1 && arr[j] === 2) {
              res[i][j] = "+";
              res[j][i] = "-";
            } else if (arr[i] === 2 && arr[j] === 1) {
              res[i][j] = "-";
              res[j][i] = "+";
            } else if (flag === 0) {
              res[i][j] = "+";
              res[j][i] = "-";
              flag = 1;
            } else {
              res[i][j] = "-";
              res[j][i] = "+";
            }
          }
        }
      }
      console.log("YES");
      for (let i = 0; i < res.length; i++) console.log(res[i].join(" "));
    }
  }
};
solve();


You are given a decimal representation of an integer $$$x$$$ without leading zeros.You have to perform the following reduction on it exactly once: take two neighboring digits in $$$x$$$ and replace them with their sum without leading zeros (if the sum is $$$0$$$, it's represented as a single $$$0$$$).For example, if $$$x = 10057$$$, the possible reductions are:   choose the first and the second digits $$$1$$$ and $$$0$$$, replace them with $$$1+0=1$$$; the result is $$$1057$$$;  choose the second and the third digits $$$0$$$ and $$$0$$$, replace them with $$$0+0=0$$$; the result is also $$$1057$$$;  choose the third and the fourth digits $$$0$$$ and $$$5$$$, replace them with $$$0+5=5$$$; the result is still $$$1057$$$;  choose the fourth and the fifth digits $$$5$$$ and $$$7$$$, replace them with $$$5+7=12$$$; the result is $$$10012$$$. What's the largest number that can be obtained?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each testcase consists of a single integer $$$x$$$ ($$$10 \le x < 10^{200000}$$$). $$$x$$$ doesn't contain leading zeros. The total length of the decimal representations of $$$x$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the largest number that can be obtained after the reduction is applied exactly once. The number should not contain leading zeros.

NoteThe first testcase of the example is already explained in the statement.In the second testcase, there is only one possible reduction: the first and the second digits.

const solve = n=>{
   let max = 0,index = 0,res="";
     for(let i=n.length-1;i>0;i--){
          let t  = parseInt(n[i]) + parseInt(n[i-1]);
          if(t>=10){
               max = t;
               index = i-1;
               break;
          }
          else{
               if(t>=n[i-1]){
                    max = t;
                    index = i-1;
               }
          }
     }
     for(let i=0;i<n.length;i++){
          if(index===i){
               res+=max;
               i+=1;
          }
          else res+=n[i];
     }
     console.log(res);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = readline();
       solve(n);
  }
}
main();

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

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

  //------------------------------ <Solution> -------------------------------//
  let t = inputReader.readNumber();
  //let t = 1;

  function solve() {
    let s = inputReader.readLine().split("");
    let n = s.map((x) => {
      return Number(x);
    });
    for (let i = n.length - 1; i > 0; i--) {
      if (n[i] + n[i - 1] >= 10) {
        let sum = n[i] + n[i - 1];
        n[i - 1] = Math.floor(sum / 10);
        n[i] = sum % 10;
        console.log(n.join(""));
        return;
      }
    }
    n[1] += n[0];
    n.shift();
    console.log(n.join(""));
  }

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

  //------------------------------ <Solution> -------------------------------//
}

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 readLine() {
    return _inputLines[_lineNumber++];
  }

  return {
    readNumber,
    readLine,
  };
}

const main = () => {

	var t = readInt();
	while (t--) {
		var s = readline();
		var n = s.length;
		var found = false;
		for (var i = n - 2; i >= 0; i--) {
			// find rightmost instance where s[i] and s[i + 1] >= 10
			if (parseInt(s[i]) + parseInt(s[i + 1]) >= 10) {
				var middle = (parseInt(s[i]) + parseInt(s[i + 1])).toString();
				print(s.slice(0, i) + middle + s.slice(i + 2, n));
				found = true;
				break;
			}
		}
		if (found === false) {
			// string must shorten. merge 1st 2 chars for largest result
			var front = (parseInt(s[0]) + parseInt(s[1])).toString();
			print(front + s.slice(2, n));
		}
	}

	return;
}

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

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

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

const solve = n=>{
   let max = 0,index = 0,res="";
     for(let i=n.length-1;i>0;i--){
          let t  = parseInt(n[i]) + parseInt(n[i-1]);
          if(t>10){
               max = t;
               index = i-1;
               break;
          }
          else{
               if(t>=n[i-1]){
                    max = t;
                    index = i-1;
               }
          }
     }
     for(let i=0;i<n.length;i++){
          if(index===i){
               res+=max;
               i+=1;
          }
          else res+=n[i];
     }
     console.log(res);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = readline();
       solve(n);
  }
}
main();