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

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

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

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

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

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


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

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

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

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


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


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

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


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

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


for(t=readline();t--;){
    x=readline(),y=readline()
    for(i=x.length-1,p=y.length-1;i>-1;i--)~p&&x[i]==y[p]?p--:i--;
    print(~p?'NO':'YES')
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main(){
  const tests_count = parseInt(readline());
  for (var test = 0; test < tests_count; test++) {
    const src = readline();
    const pat = readline();
    console.log(verify(src, pat, 0) || verify(src, pat, 1) ? "YES" : "NO")
  }
}

function verify(src, pat, parity) {
  let src_idx = findNextWithParity(src, 0, pat[0], parity);
  if (src_idx >= src.length)
    return false;

  let pat_idx = 1;
  while (pat_idx < pat.length) {
    parity = 1 - src_idx % 2
    // El índice debe tener una paridad diferente al elemento actual (para que la diferencia sea divisible por 2)
    src_idx = findNextWithParity(src, src_idx + 1, pat[pat_idx], parity);
    if (src_idx >= src.length)
      return false;

    pat_idx++
  }
  return (src.length - src_idx)%2==1;
}
function findNextWithParity(src, idx, c, parity) {
  idx = findNext(src, idx, c);
  while (idx < src.length && (idx % 2 !== parity))
    idx = findNext(src, idx + 1, c);
  return idx;
}
function findNext(src, idx, c) {
  while (idx < src.length && c !== src[idx]) idx++;
  return idx;
}

function solution(s, t) {
  const m = s.length, n = t.length
  if (m < n) return false
  let i = m - 1, j = n - 1
  const delFirstOfS = (m - n) & 1
  const smallestIdxOfS = delFirstOfS ? 1 : 0
  while(i >= smallestIdxOfS && j >= 0) {
    if(s[i] === t[j]) {
      i--
      j--
    } else {
      i -= 2
    }
    if (j < 0) return true
  }
  return false
}

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
const resArr = []

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 3) {
    const t = input.pop()
    const s = input.pop()
    const res = solution(s, t)
    resArr.push(res ? 'YES' : 'NO')
  }
});
rl.on("close", () => {
  resArr.forEach(e => console.log(e))
});

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }

  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i += 2) {
      if (subS[i] === subT[0]) {
        subS = subS.substring(i + 1);
        subT = subT.substring(1);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }
    if (!foundNextStep) {
      return 'NO';
    }
    if (newLengthDiff === 0) {
      return subS === subT ? 'YES' : 'NO';
    }
    if (subT.length === 0) {
      if (subS.length % 2) {
        console.log(subS);
      }
      return 'YES';
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

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();
  function solve() {
    let s = inputReader.readLine().split("");
    let t = inputReader.readLine().split("");
    if (s.length < t.length) {
      console.log("NO");
      return;
    }
    let i = s.length - 1,
      j = t.length - 1;
    while (i >= 0 && j >= 0) {
      if (s[i] == t[j]) {
        i--;
        j--;
      } else {
        i -= 2;
      }
    }
    //console.log([i, j]);
    if (j >= 0) {
      console.log("NO");
    } else console.log("YES");
  }

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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Node.js template for
    the coding contests.

            ~~*/
        'use strict';
            /*~~

    Tip:
    Don't raise your voice,
    improve your argument.

            ~~~~

   cat /dev/ass > /dev/head
           Ctrl+C
  cat /knowledge > /dev/head

               © Yakov Gellert
                       frvr.ru

~~~~Don't~touch~that~part:~~*/

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

let inputString = '',
    currentLine = 0,
    outputString = '';

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

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

    /*
     * Running a solution function
     * with whole input as an array
     * and a string for a buffered output
     */
    solution(inputString, outputString);

    /*
     * Return a buffered output
     */
    write(outputString);
});

/* Read a line from stdin */
function readline() {
    if (currentLine < inputString.length) {
        return inputString[currentLine++];
    }

    return '';
}

/* Read array from stdin */
function readarr() {
    return readline().split(' ');
}

/* Read numbers from stdin */
function readnums() {
    return readarr().map(num => parseInt(num));
}

/* Write a string to stdout */
function write(data) {
    data = data.toString();
    process.stdout.write(data);

    return data;
}

/* Write a string with \n to stdout */
function writeline(data) {
    write(data.toString() + '\n');
}

/* Append a string to a buffer */
function fwrite(data) {
    outputString += data.toString() + ' ';
}

/* Append a string with \n to a buffer */
function fwriteline(data) {
    fwrite(data);
    outputString += '\n';
}

/* Throw an error */
function error(name) {
    throw new Error(name.toString());
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Write your solution here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function solution(input, output) {

    for (let cases = readnums()[0]; cases > 0; cases -= 1) {
        let sample = readline().split('').reverse().join(''),
            target = readline().split('').reverse().join(''),
            sampleI = 0,
            targetI = 0;

        if (target.length > sample.length) {
            fwriteline("NO");
            continue;
        }

        while (targetI < target.length && sampleI < sample.length) {
            if (target[targetI] === sample[sampleI]) {
                sampleI += 1;
                targetI += 1;
                continue;
            }

            sampleI += 2;
        }

        fwriteline(targetI === target.length ? "YES" : "NO");
    }
}

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--) {
		let s = rl();
		let t = rl();

		let i = s.length - 1, j = t.length - 1;
		while (i >= 0 && j >= 0) {
			if (s[i] == t[j]) {
				i--; j--;
			} else {
				i -= 2;
			}
		}

		const ans = j < 0;

		console.log(ans ? 'YES' : 'NO');
	}
}

for(t=readline();t--;){
    x=readline(),y=readline()
    for(i=x.length-1, p=y.length-1; ~p && i>-1; i--) {
        ~p && x[i] == y[p] ? p-- : i--;
    }
    print(~p?'NO':'YES')
}

for(t=readline();t--;){
    x=readline(),y=readline()
    for(i=x.length-1, p=y.length-1; i>-1; i--) {
        ~p && x[i] == y[p] ? p-- : i--;
    }
    print(~p?'NO':'YES')
}

for (var n = Number (readline ()); n > 0; n--)
    {
    var s = readline ();
    var t = readline ();
    var i = s.length - 1;
    var j = t.length - 1;

    while (i >= j && j >= 0)
        {
        if (s[i] === t[j]) { i--; j--; }
        else { i -= 2; }
        }

    print (j < 0 ? "Yes" : "No");
    }

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  if (m > n) return 'NO';
  const check = (i, j = 1) => {
    let flag = i & 1 ^ 1;
    for (; i < n && j < m; i++) {
      if (a[i] === b[j] && (i & 1) !== flag) {
        j++;
        flag ^= 1;
      }
    }
    return j === m && !(n - i & 1);
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i + 1)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i + 1)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const tests_count = parseInt(readline());
  for (var test = 0; test < tests_count; test++) {
    const text = readline();
    const pattern = readline();
    console.log(verifyPattern(text, pattern, 0) || verifyPattern(text, pattern, 1) ? "YES" : "NO")
  }
}

function verifyPattern(text, pattern, parity) {
  let text_idx = parity - 1;
  for (let pattern_idx = 0; pattern_idx < pattern.length; pattern_idx++) {
    text_idx = findNextWithParity(text, text_idx + 1, pattern[pattern_idx]);
    if (text_idx >= text.length)
      return false;
  }
  return (text.length - text_idx) % 2 == 1;
}
function findNextWithParity(src, idx, c) {
  while (idx < src.length && c !== src[idx]) idx += 2;
  return idx;
}

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

function main() {
  const tests_count = parseInt(readline());
  for (var test = 0; test < tests_count; test++) {
    const text = readline();
    const pattern = readline();
    console.log(verifyPattern(text, pattern, 0) || verifyPattern(text, pattern, 1) ? "YES" : "NO")
  }
}

function verifyPattern(text, pattern, parity) {
  let pattern_idx = 0;
  let text_idx = parity-1;
  while (pattern_idx < pattern.length) {
    text_idx = findNextWithParity(text, text_idx + 1, pattern[pattern_idx]);
    if (text_idx >= text.length)
      return false;
    pattern_idx++
  }
  return (text.length - text_idx) % 2 == 1;
}
function findNextWithParity(src, idx, c) {
  while (idx < src.length && c !== src[idx]) idx += 2;
  return idx;
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var dbg = s.startsWith('fwnzzvuqoqfxzgicxplljpoitnkkjvrsdpighivrvnawrc');
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }
  if (dbg) {
    print('sLe: ' + sLength + ' - tLe: ' + tLength);
  }
  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i += 2) {
      if (subS[i] === subT[0]) {
        subS = subS.substring(i + 1);
        subT = subT.substring(1);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }
    if (!foundNextStep) {
      return 'NO';
    }
    if (newLengthDiff === 0) {
      return subS === subT ? 'YES' : 'NO';
    }
    if (subT.length === 0) {
      if (subS.length % 2) {
        console.log(subS);
      }
      return 'YES';
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var dbg = tLength > 40000 && sLength > 40000 && sLength !== 49912;
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }

  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      if (i % 2 === 0 && subS[i] === subT[0]) {
        var lengthLeft = newLengthDiff - i;
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          branches.push({ subT, subS: subS.substring(i + 2) });
        }
        var groupLen;
        var prevTryLen = 1;
        var tryLen = lengthLeft;
        var nextTryLen = lengthLeft;
        subS = subS.substring(i);
        while (!groupLen) {
          var lengthMatches = subS.startsWith(subT.substring(0, tryLen));
          if (lengthMatches && lengthLeft === tryLen) {
            groupLen = tryLen;
          }
          // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));
          if (!lengthMatches) {
            nextTryLen = Math.floor(tryLen - Math.abs(tryLen - prevTryLen) / 2);
          } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {
            nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);
          } else {
            groupLen = tryLen;
          }
          prevTryLen = tryLen;
          tryLen = nextTryLen;
          if (prevTryLen === nextTryLen) {
            groupLen = Math.max(tryLen - 1, 1);
          }
        }
        if (dbg) {
          print('groupLen: ' + groupLen + ' - sLe: ' + sLength + ' - tLe: ' + tLength);
        }
        subS = subS.substring(groupLen);
        subT = subT.substring(groupLen);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {
      if (subS === subT || (subS.length % 2 === 0 && subT.length === 0)) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      // console.log('roadNotTaken', roadNotTaken)
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var dbg = tLength > 40000 && sLength > 40000;
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }

  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      if (i % 2 === 0 && subS[i] === subT[0]) {
        var lengthLeft = newLengthDiff - i;
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          branches.push({ subT, subS: subS.substring(i + 2) });
        }
        var groupLen;
        var prevTryLen = 1;
        var tryLen = lengthLeft;
        var nextTryLen = lengthLeft;
        subS = subS.substring(i);
        while (!groupLen) {
          var lengthMatches = subS.startsWith(subT.substring(0, tryLen));
          if (lengthMatches && lengthLeft === tryLen) {
            groupLen = tryLen;
          }
          // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));
          if (!lengthMatches) {
            nextTryLen = Math.floor(tryLen - Math.abs(tryLen - prevTryLen) / 2);
          } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {
            nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);
          } else {
            groupLen = tryLen;
          }
          prevTryLen = tryLen;
          tryLen = nextTryLen;
          if (prevTryLen === nextTryLen) {
            groupLen = Math.max(tryLen - 1, 1);
          }
        }
        if (dbg) {
          print('groupLen: ' + groupLen + ' - sLe: ' + sLength + ' - tLe: ' + tLength);
        }
        subS = subS.substring(groupLen);
        subT = subT.substring(groupLen);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {
      if (subS === subT || (subS.length % 2 === 0 && subT.length === 0)) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      // console.log('roadNotTaken', roadNotTaken)
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }

  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      if (i % 2 === 0 && subS[i] === subT[0]) {
        var lengthLeft = newLengthDiff - i;
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          branches.push({ subT, subS: subS.substring(i + 2) });
        }
        var groupLen = 1;
        var prevTryLen = 1;
        var tryLen = lengthLeft;
        var nextTryLen = lengthLeft;
        subS = subS.substring(i);
        // while (!groupLen) {
        //   var lengthMatches = subS.startsWith(subT.substring(0, tryLen));
        //   if (lengthMatches && lengthLeft === tryLen) {
        //     groupLen = tryLen;
        //   }
        //   // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));
        //   if (!lengthMatches) {
        //     nextTryLen = Math.floor((prevTryLen + tryLen) / 2);
        //   } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {
        //     nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);
        //   } else {
        //     groupLen = tryLen;
        //   }
        //   prevTryLen = tryLen;
        //   tryLen = nextTryLen;
        //   if (prevTryLen === nextTryLen) {
        //     groupLen = Math.max(tryLen - 1, 1);
        //   }
        // }
        subS = subS.substring(i + groupLen);
        subT = subT.substring(groupLen);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {
      if (subS === subT || (subS.length % 2 === 0 && subT.length === 0) || subS.startsWith(subT)) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;

  // for (var i = parityMatch; i <= newLengthDiff; i += 2) {
  //   if (s.substring(i, t.length) === t) {
  //     return 'Yes';
  //   }
  // }

  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      if (i % 2 === 0 && subS[i] === subT[0]) {
        var lengthLeft = newLengthDiff - i;
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          branches.push({ subT, subS: subS.substring(i + 2) });
        }
        var groupLen;
        var prevTryLen = 1;
        var tryLen = lengthLeft;
        var nextTryLen = lengthLeft;
        subS = subS.substring(i);
        while (!groupLen) {
          var lengthMatches = subS.startsWith(subT.substring(0, tryLen));
          if (lengthMatches && lengthLeft === tryLen) {
            groupLen = tryLen;
          }
          // var lengthMin1Matches = subS.startsWith(subT.substring(0, tryLen - 1));
          if (!lengthMatches) {
            nextTryLen = Math.floor((prevTryLen + tryLen) / 2);
          } else if (subS.startsWith(subT.substring(0, tryLen + 1))) {
            nextTryLen = Math.floor(tryLen + Math.abs(tryLen - prevTryLen) / 2);
          } else {
            groupLen = tryLen;
          }
          prevTryLen = tryLen;
          tryLen = nextTryLen;
          if (prevTryLen === nextTryLen) {
            groupLen = Math.max(tryLen - 1, 1);
          }
        }
        subS = subS.substring(i + groupLen);
        subT = subT.substring(groupLen);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length % 2 === 0)) {
      if (subS === subT || (subS.length % 2 === 0 && subT.length === 0) || subS.startsWith(subT)) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var freqS = {};
  var freqT = {};
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  Array.from(subS).forEach(function (sC) {
    freqS[sC] = (freqS[sC] || 0) + 1;
  });
  Array.from(subT).forEach(function (tC) {
    freqT[tC] = (freqT[tC] || 0) + 1;
  });
  var issueLetter = Object.keys(freqT).find(function (k) {
    return freqT[k] > (freqS[k] || 0);
  });
  if (issueLetter) {
    return 'NO';
  }

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;
  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      var sC = subS[i];
      freqS[sC]--;

      if (i % 2 === 0 && subS[i] === subT[0]) {
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          var sCP1 = subS[i + 1];
          var savedFreqS = Object.assign({}, freqS);
          var savedFreqT = Object.assign({}, freqT);
          savedFreqS[sCP1]--;
          if (!freqT[sCP1] || freqT[sCP1] <= savedFreqS[sCP1]) {
            branches.push({
              subT, subS: subS.substring(i + 2), savedFreqS, savedFreqT,
            });
          }
        }
        freqT[subT[0]] -= 1;
        subS = subS.substring(i + 1);
        subT = subT.substring(1);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
      if (freqT[sC] > freqS[sC]) {
        // console.log('SUB_S: ', subS);
        // console.log('SUB_T: ', subT);
        // console.log('I: ', i);
        // console.log(sC, freqT[sC], freqS[sC]);
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || subT.length === 0) {
      if (subS === subT) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
      freqS = roadNotTaken.savedFreqS;
      freqT = roadNotTaken.savedFreqT;
    }
    foundNextStep = false;
  }
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var freqS = {};
  var freqT = {};
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;

  Array.from(subS).forEach(function (sC) {
    freqS[sC] = (freqS[sC] || 0) + 1;
  });
  Array.from(subT).forEach(function (tC) {
    freqT[tC] = (freqT[tC] || 0) + 1;
  });
  var issueLetter = Object.keys(freqT).find(function (k) {
    return freqT[k] > (freqS[k] || 0);
  });
  if (issueLetter) {
    return 'NO';
  }

  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;
  while (subT.length) {
    for (var i = 0; i <= newLengthDiff; i++) {
      var sC = subS[i];
      freqS[sC]--;
      if (freqT[sC] > freqS[sC]) {
        break;
      }

      if (i % 2 === 0 && subS[i] === subT[0]) {
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2 && subS.substring(i + 2).includes(subT[0])) {
          var sCP1 = subS[i + 1];
          var savedFreqS = Object.assign({}, freqS);
          var savedFreqT = Object.assign({}, freqT);
          savedFreqS[sCP1]--;
          if (!freqT[sCP1] || freqT[sCP1] <= savedFreqS[sCP1]) {
            branches.push({
              subT, subS: subS.substring(i + 2), savedFreqS, savedFreqT,
            });
          }
        }
        freqT[subT[0]] -= 1;
        subS = subS.substring(i + 1);
        subT = subT.substring(1);
        newLengthDiff = subS.length - subT.length;
        foundNextStep = true;
        break;
      }
    }

    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length !== 0)) {
      if (subS === subT) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
      freqS = roadNotTaken.savedFreqS;
      freqT = roadNotTaken.savedFreqT;
    }
    foundNextStep = false;
  }
}

var amount = parseInt(readline());
for (var i = 0; i < amount; i++) {
  print(test(readline(), readline()));
}

function test(s, t) {
  var sLength = s.length;
  var tLength = t.length;
  if (tLength > sLength) return 'NO';
  var lengthDiff = sLength - tLength;
  var parityMatch = lengthDiff % 2;
  var subS = parityMatch === 1 ? s.substring(1) : s;
  var subT = t;
  var branches = [];
  var foundNextStep = false;
  var newLengthDiff = lengthDiff - parityMatch;
  var loopNr = 0;
  while (subT.length) {
    if (loopNr === 100000) {
      print(`B:${branches.length}, S:${s.length}, L:${t.length}`);
    }
    for (var i = 0; i <= newLengthDiff; i += 2) {
      if (subS[i] === subT[0]) {
        foundNextStep = true;
        if (newLengthDiff - i - 2 >= 0 && subS.length > i + 2) {
          branches.push({ subT, subS: subS.substring(i + 2) });
        }
        subS = subS.substring(i + 1);
        subT = subT.substring(1);
        newLengthDiff = subS.length - subT.length;
        break;
      }
    }
    if (!foundNextStep || newLengthDiff === 0 || (subT.length === 0 && subS.length !== 0)) {
      if (subS === subT) {
        return 'YES';
      }
      var roadNotTaken = branches.pop();
      if (!roadNotTaken) {
        return 'NO';
      }
      // print(roadNotTaken);
      subS = roadNotTaken.subS;
      subT = roadNotTaken.subT;
    }
    foundNextStep = false;
  }
}

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  if (m > n) return 'NO';
  const check = (i, j = 1) => {
    let flag = i & 1;
    for (let k = i + 1; k < n && j < m; k++) {
      if (a[k] === b[j] && (k & 1) !== flag) {
        j++;
        flag ^= 1;
      }
    }
    return j === m;
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  if (m > n) return 'NO';
  const check = (i, j) => {
    let pre = i & 1;
    j++;
    for (let k = i + 1; k < n; k++) {
      if (a[k] === b[j] && (k & 1) !== pre) {
        j++;
        pre ^= 1;
      }
      if (j === m) return true;
    }
    return j === m;
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  const check = (i, j) => {
    let pre = i & 1;
    j++;
    for (let k = i + 1; k < n; k++) {
      if (a[k] === b[j] && (k & 1) !== pre) {
        j++;
        pre ^= 1;
      }
      if (j === m) return true;
    }
    return j === m;
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  const check = (i, j) => {
    let pre = i;
    j++;
    for (let k = i + 1; k < n; k++) {
      if (a[k] === b[j] && (k - pre - 1) % 2 === 0) {
        j++;
        pre = k;
      }
      if (j === m) return true;
    }
    return j === m;
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

function solve(a, b) {
  const n = a.length,
        m = b.length;
  const check = (i, j) => {
    let pre = i;
    j++;
    for (let k = i + 1; k < n; k++) {
      if (a[k] === b[j] && (k - pre - 1) % 2 === 0) {
        j++;
        pre = k;
      }
      if (j === m) return true;
    }
    return false;
  };
  for (let i = 0; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  for (let i = 1; i < n; i += 2) {
    if (a[i] === b[0]) {
      if (check(i, 0)) return 'YES';
      break;
    }
  }
  return 'NO';
}

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main(){
  const tests_count = parseInt(readline());
  for (var test = 0; test < tests_count; test++) {
    const src = readline() || "";
    const pat = readline() || "";
    console.log(verify(src, pat, 0) || verify(src, pat, 1) ? "YES" : "NO")
  }
}

function verify(src, pat, parity) {
  if (pat.length === 0)
    return true;

  let src_idx = findNextWithParity(src, 0, pat[0], parity);
  if (src_idx >= src.length)
    return false;

  let pat_idx = 1;
  while (pat_idx < pat.length) {
    parity = 1 - src_idx % 2
    // El índice debe tener una paridad diferente al elemento actual (para que la diferencia sea divisible por 2)
    src_idx = findNextWithParity(src, src_idx + 1, pat[pat_idx], parity);
    if (src_idx >= src.length)
      return false;

    pat_idx++
  }
  return true;
}
function findNextWithParity(src, idx, c, parity) {
  idx = findNext(src, idx, c);
  while (idx < src.length && (idx % 2 !== parity))
    idx = findNext(src, idx + 1, c);
  return idx;
}
function findNext(src, idx, c) {
  while (idx < src.length && c !== src[idx]) idx++;
  return idx;
}

function solution(s, t) {
  const m = s.length, n = t.length
  if (m < n) return false
  let i = m - 1, j = n - 1
  const delFirstOfS = (m - n) & 1
  const smallestIdxOfS = delFirstOfS ? 1 : 0
  while(i >= smallestIdxOfS && j >= 0) {
    if(s[i] === t[j]) {
      i--
      j--
    } else {
      i -= 2
    }
    if (j < 0) return true
  }
  return false
}

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 3) {
    const t = input.pop()
    const s = input.pop()
    const res = solution(s, t)
    console.log(res ? 'YES' : 'NO')
  }
});
rl.on("close", () => {
});

function solution(s, t) {
  const m = s.length, n = t.length
  if (m < n) return false
  let i = m - 1, j = n - 1
  const delFirstOfS = (m - n) & 1
  const smallestIdxOfS = delFirstOfS ? 1 : 0
  while(i >= smallestIdxOfS && j >= 0) {
    if(s[i] === t[j]) {
      i--
      j--
    } else {
      i -= 2
    }
  }
  return j === -1
}
const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 3) {
    const t = input.pop()
    const s = input.pop()
    const res = solution(s, t)
    console.log(res ? 'YES' : 'NO')
  }
});
rl.on("close", () => {
});

function solution(s, t) {
  const m = s.length, n = t.length
  if (m < n) return false
  let i = m - 1, j = n - 1

  while(i >= 0 && j >= 0) {
    if(s[i] === t[j]) {
      i--
      j--
    } else {
      i -= 2
    }
  }
  return j === -1
}

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];

rl.on("line", (line) => {
  input.push(line);
  if (input.length === 3) {
    const t = input.pop()
    const s = input.pop()
    const res = solution(s, t)
    console.log(res ? 'YES' : 'NO')
  }
});
rl.on("close", () => {
});

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();
  function solve() {
    let s = inputReader.readLine().split("");
    let t = inputReader.readLine().split("");
    if (s.length < t.length) {
      console.log("NO");
      return;
    }
    let i = s.length - 1,
      j = t.length - 1;
    while (i >= 0 && j >= 0) {
      if (s[i] == t[j]) {
        i--;
        j--;
      } else {
        i -= 2;
      }
    }
    //console.log([i, j]);
    if (j > 0) {
      console.log("NO");
    } else console.log("YES");
  }

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

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();
  function solve() {
    let s = inputReader.readLine().split("");
    let t = inputReader.readLine().split("");
    if (s.length < t.length) {
      console.log("NO");
      return;
    }
    let i = s.length - 1,
      j = t.length - 1;
    while (i >= 0 && j >= 0) {
      if (s[i] == t[j]) {
        i--;
        j--;
      } else {
        i -= 2;
      }
    }
    //console.log([i, j]);
    if (j > 0 && i < 0) {
      console.log("NO");
    } else console.log("YES");
  }

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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Node.js template for
    the coding contests.

            ~~*/
        'use strict';
            /*~~

    Tip:
    Don't raise your voice,
    improve your argument.

            ~~~~

   cat /dev/ass > /dev/head
           Ctrl+C
  cat /knowledge > /dev/head

               © Yakov Gellert
                       frvr.ru

~~~~Don't~touch~that~part:~~*/

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

let inputString = '',
    currentLine = 0,
    outputString = '';

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

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

    /*
     * Running a solution function
     * with whole input as an array
     * and a string for a buffered output
     */
    solution(inputString, outputString);

    /*
     * Return a buffered output
     */
    write(outputString);
});

/* Read a line from stdin */
function readline() {
    if (currentLine < inputString.length) {
        return inputString[currentLine++];
    }

    return '';
}

/* Read array from stdin */
function readarr() {
    return readline().split(' ');
}

/* Read numbers from stdin */
function readnums() {
    return readarr().map(num => parseInt(num));
}

/* Write a string to stdout */
function write(data) {
    data = data.toString();
    process.stdout.write(data);

    return data;
}

/* Write a string with \n to stdout */
function writeline(data) {
    write(data.toString() + '\n');
}

/* Append a string to a buffer */
function fwrite(data) {
    outputString += data.toString() + ' ';
}

/* Append a string with \n to a buffer */
function fwriteline(data) {
    fwrite(data);
    outputString += '\n';
}

/* Throw an error */
function error(name) {
    throw new Error(name.toString());
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Write your solution here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function solution(input, output) {

    for (let cases = readnums()[0]; cases > 0; cases -= 1) {
        let sample = readline();
        let target = readline();

        let checkEqualityAndWrite = (
            (s, t) => fwriteline(s === t ? "YES" : "NO"));

        /*
         * t is larger than s, can't reach it
         */
        if (target.length > sample.length) {
            fwriteline("NO");
            continue;
        }

        if (target.length === sample.length) {
            checkEqualityAndWrite(target, sample);
            continue;
        }

        /*
         * Trying to find first symbol of the target in the sample
         */
        let sampleI = 0,
            targetI = 0;

        for (; sampleI < sample.length; sampleI += 1) {
            if (sample[sampleI] === target[targetI]) {
                sampleI += 1;
                targetI += 1;

                break;
            }
        }

        /*
         * Found none — failure!
         */
        if (targetI === 0) {
            fwriteline("NO");
            continue;
        }

        /*
         * Now, my main algo:
         * 1. find target's letter position in a sample (if none — failure)
         * 2. check if it's distance from the start of the current search is an even/odd number
         * 2.1. if even — great, start over with first step for the next letter in target
         * 2.2. if odd — retry first (1.) step, but for the same letter in target
         */
        let failure = 0;
        let currentI = sampleI;

        while (sampleI < sample.length && targetI < target.length) {
            let found = 0;

            while (sampleI < sample.length) {
                if (sample[sampleI] === target[targetI]) {
                    found = 1;
                    break;
                }

                sampleI += 1;
            }

            if (found === 0) {
                failure = 1;
                break;
            }

            if ((sampleI - currentI) % 2 === 0) {
                targetI += 1;
                currentI = sampleI + 1;
            }

            sampleI += 1;
        }

        if (failure === 1) {
            fwriteline("NO");
            continue;
        }

        /*
         * If we walked through all symbols of the target, but not the sample,
         * we just need to check the distance from last checked symbol in sample until the end of it.
         * If it's even — great, we can trim all of them.
         * If it's odd — failure, because we couldn't trim them without removing last checked symbol or adding extra one
         * to the sample sequence thus mismatching the target one.
         */
        if (sampleI < sample.length) {
            /*
             * +1, because of 0-notation
             * -1, to revert the last +1 at the end of a while cycle above
             */
            checkEqualityAndWrite((sample.length - sampleI) % 2, 0);
        }

        /*
         * Got to the end — great!
         */
        fwriteline("YES");
    }
}