You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.Consider a number axis. The capital of your empire is initially at $$$0$$$. There are $$$n$$$ unconquered kingdoms at positions $$$0<x_1<x_2<\ldots<x_n$$$. You want to conquer all other kingdoms.There are two actions available to you:   You can change the location of your capital (let its current position be $$$c_1$$$) to any other conquered kingdom (let its position be $$$c_2$$$) at a cost of $$$a\cdot |c_1-c_2|$$$.  From the current capital (let its current position be $$$c_1$$$) you can conquer an unconquered kingdom (let its position be $$$c_2$$$) at a cost of $$$b\cdot |c_1-c_2|$$$. You cannot conquer a kingdom if there is an unconquered kingdom between the target and your capital. Note that you cannot place the capital at a point without a kingdom. In other words, at any point, your capital can only be at $$$0$$$ or one of $$$x_1,x_2,\ldots,x_n$$$. Also note that conquering a kingdom does not change the position of your capital.Find the minimum total cost to conquer all kingdoms. Your capital can be anywhere at the end.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. The description of each test case follows. The first line of each test case contains $$$3$$$ integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq a,b \leq 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \leq x_1 < x_2 < \ldots < x_n \leq 10^8$$$). The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer  — the minimum cost to conquer all kingdoms.

NoteHere is an optimal sequence of moves for the second test case:  Conquer the kingdom at position $$$1$$$ with cost $$$3\cdot(1-0)=3$$$.  Move the capital to the kingdom at position $$$1$$$ with cost $$$6\cdot(1-0)=6$$$.  Conquer the kingdom at position $$$5$$$ with cost $$$3\cdot(5-1)=12$$$.  Move the capital to the kingdom at position $$$5$$$ with cost $$$6\cdot(5-1)=24$$$.  Conquer the kingdom at position $$$6$$$ with cost $$$3\cdot(6-5)=3$$$.  Conquer the kingdom at position $$$21$$$ with cost $$$3\cdot(21-5)=48$$$.  Conquer the kingdom at position $$$30$$$ with cost $$$3\cdot(30-5)=75$$$. The total cost is $$$3+6+12+24+3+48+75=171$$$. You cannot get a lower cost than this.

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

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

const calc = (n, a, b, x)=>{
  let A = BigInt(a)
  let B = BigInt(b)
  let conc = new Set();
  let moved = 0;
  let total_sum = BigInt(0)

  for (let i=0; i<n; i++){
    total_sum += BigInt(x[i]);
  }
  let res = total_sum*B;
  let walk_dist = (0);
  let walk_cost = BigInt(0);
  let prev = 0;
  for (let i=0; i<n; i++){
    let diff = BigInt(x[i]-prev)
    walk_cost += (diff*B+diff*A);
    total_sum -= BigInt(n-i)*diff;
    let cur = walk_cost + total_sum*B
    if (cur<res)
      res = cur;
    prev = x[i]
  }
  return res.toString();
};

function main() {
    let T = +readline()
    while (T--){
      let [n, a, b] = ra(); // b < r
      let x = ra()
      l('ans')
      print(calc(n, a, b, x));
    }
}

E.calc = calc;

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

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

function div(val, by){
    return (val - val % by) / by;
}

const calc = (n, a, b, x)=>{
    const moveCost = (x1, x2) => {
        return BigInt(a) * BigInt(Math.abs(x2 - x1));
    }
    const conquerCost = (x1, x2) => {
        return BigInt(b) * BigInt(Math.abs(x2 - x1));
    }
    let cost = BigInt(0);
    for (let i = 0; i < n; i++) {
        cost += conquerCost(0, x[i]);
    }
    let pos = 0;
    for (let i = 0; i < n - 1; i++) {
        let mv = moveCost(pos, x[i]);
        let ptsRight = BigInt(n - i - 1);
        let reduction = ptsRight * conquerCost(pos, x[i]);
        if (cost - reduction + mv <= cost) {
            pos = x[i];
            cost = cost - reduction + mv;
        }
    }
    return cost;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, a, b] = ra();
        let x = ra();
        console.log(`${calc(n, a, b, x)}`);
    }
}

const readline = require('readline')

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

function solve(n, a, b, arr) {
    // const suffix = []
    // for (let i = arr.length - 1; i >= 0; i--) {
    //     const now = arr[i] - arr[n - 1]
    //     suffix[i] = i === arr.length - 1 ? now : now + suffix[i + 1]
    // }
    //
    let ans = 0
    let c = 0
    for (let i = 0; i < n; i++) {
        const x = arr[i]
        const p = arr[i - 1] || 0
        const p1 = a
        const p2 = (n - i) * b
        const c1 = a * (p - c) + b * (x - p)
        const c2 = b * (x - c)
        if (p1 <= p2) {
        // if (c1 <= c2) {
            c = p
            ans += c1
        } else {
            ans += c2
        }
    }
    return ans
}


There was a string $$$s$$$ which was supposed to be encrypted. For this reason, all $$$26$$$ lowercase English letters were arranged in a circle in some order, afterwards, each letter in $$$s$$$ was replaced with the one that follows in clockwise order, in that way the string $$$t$$$ was obtained. You are given a string $$$t$$$. Determine the lexicographically smallest string $$$s$$$ that could be a prototype of the given string $$$t$$$.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ of the same length if and only if:   in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter, that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^4$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$t$$$. The next line contains the string $$$t$$$ of the length $$$n$$$, containing lowercase English letters. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output a single line containing the lexicographically smallest string $$$s$$$ which could be a prototype of $$$t$$$.

5

1

a

2

ba

10

codeforces

26

abcdefghijklmnopqrstuvwxyz

26

abcdefghijklmnopqrstuvwxzy

b
ac
abcdebfadg
bcdefghijklmnopqrstuvwxyza
bcdefghijklmnopqrstuvwxyaz

NoteIn the first test case, we couldn't have the string "a", since the letter a would transit to itself. Lexicographically the second string "b" is suitable as an answer.In the second test case, the string "aa" is not suitable, since a would transit to itself. "ab" is not suitable, since the circle would be closed with $$$2$$$ letters, but it must contain all $$$26$$$. The next string "ac" is suitable.Below you can see the schemes for the first three test cases. The non-involved letters are skipped, they can be arbitrary placed in the gaps.

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  rn();
        const a = read();
  const res = [],
        map = new Map(),
        map1 = new Map();
  const dfs = ch => {
    const set = new Set();
    let t = ch;
    while (t) {
      set.add(t);
      t = map.get(t);
    }
    for (let i = 0; i < 26; i++) {
      const s = String.fromCharCode(i + 97);
      if (set.has(s) || map.has(s)) continue;
      map.set(s, ch);
      map1.set(ch, s);
      return;
    }
    for (let i = 0; i < 26; i++) {
      const s = String.fromCharCode(i + 97);
      if (map.has(s)) continue;
      map.set(s, ch);
      map1.set(ch, s);
      return;
    }
  };
  for (let ch of a) {
    if (!map1.has(ch)) {
      dfs(ch);
    }
    res.push(map1.get(ch));
  }
  return res.join('');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8')
.split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!

The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.

const mainFunction = (lines) => {
    let n = lines[0].split("")
    for (let i = 0; i < n.length - 1; i++) {
        if (+n[i] % 2 === 0 && +n[n.length - 1] > +n[i]) {
            [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]
            console.log(n.join(""))
            return 0
        }
    }
    for (let i = n.length; i >= 0; i--) {
        if (+n[i] % 2 === 0 && +n[n.length - 1] < +n[i]) {
            [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]
            console.log(n.join(""))
            return 0
        }
    }
    console.log(-1)
}

const { EOL } = require('os')
if (__filename.substr(9, 4) != "azer") {
    let yourInputData = ''
    process.stdin.on('data', i => yourInputData += i)
    process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))
} else {
    const fileSystem = require("fs");
    mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))
}

var input = readline();
var indexToSwapWith = -1;
var inputLength = input.length;
for (var i =0; i< inputLength; i++) {
	if(input [i] % 2 === 0 ) {
		indexToSwapWith = i;
		if(input[i] < input[inputLength - 1]) {
			break;
		}
	}
}

if(indexToSwapWith === -1 ) {
    print (-1);
} else {
   var temp = input[indexToSwapWith];
    print(replaceChars(replaceChars(input, indexToSwapWith, input[inputLength - 1]), inputLength -1, temp));
}

function replaceChars (input, index, newValue) {
    return input.substring(0, index) + newValue + input.substring(index + 1);
}

(function() {

var s = readline().split("");

var r = -1;
var l = -1;
var z = +s[s.length-1];
for(var i = 0; i < s.length; i++) {
    var v = +s[i];
    if(v%2==0) {
        if(v<z && l==-1) l=i;
        if(v>z) r = i;
    }
}

if(r==-1 && l==-1) return print(-1);
var ind = l!=-1?l:r;
s[s.length-1] = s[ind];
s[ind] = z;
print(s.join(""));

})();

function main() {
    var s = next();

    var i, d;
    var last = s.charAt(s.length - 1) - '0';

    for (i = 0; i < s.length; i++) {
        d = s.charAt(i) - '0';
        if (d % 2 === 0 && d < last) {
            print(s.substr(0, i) + s.substr(s.length - 1, 1) + s.substr(i + 1, s.length - i - 2) + s.substr(i, 1));
            return;
        }
    }

    for (i = s.length - 1; i >= 0; i--) {
        d = s.charAt(i) - '0';
        if (d % 2 === 0) {
            print(s.substr(0, i) + s.substr(s.length - 1, 1) + s.substr(i + 1, s.length - i - 2) + s.substr(i, 1));
            return;
        }
    }

    print(-1);
}

// auxiliary code
var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(' ');
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

main();

var debug = false;

function main(lineArr) {
    var lineNum = 0;
    function readln() {
        return debug? lineArr[lineNum++] : readline();
    }
    function readints() {
       return  readln().split(' ').map(function(x) {
           return parseInt(x)
       })
    }
    function println(data) {
        debug? console.log(data) : print(data);
    }

    //***************************************
    function swap(i, j, line) {
        // lol  no swap function
        var c  = line[i];
        line[i] = line[j];
        line[j] = c;
    }
    var line = readln().split('');
    var rightMostEven = -1;
    var leftMostEvenLess = -1;
    for (var i = 0; i < line.length; i++){
        if (parseInt(line[i]) % 2 == 0) {
            rightMostEven = i;
            if (leftMostEvenLess == -1 &&
                line[i] < line[line.length - 1])
                    leftMostEvenLess = i;
        }
    }
    if (rightMostEven == -1) {
        println(-1);
        return;
    } else if (leftMostEvenLess == -1) {
        swap(line.length - 1, rightMostEven, line);
    } else  {
        swap(line.length - 1, leftMostEvenLess, line)
    }
    println(line.join(''));

}

if (debug) {
    fs = require('fs');
    var fn = '/Users/zisakadze/Projects/codeforces/js/input.txt'
    fs.readFile(fn, 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }
        main(data.split("\n"));
    });
} else {
    main();
}

var n = readline().split( "" ).map( digit => parseInt( digit, 10 ) );
var answer = -1;
var optimalEven;
var swapOdd = n[ n.length - 1 ];
for ( var i = 0; i < n.length - 1; ++i ) {
  var digit = n[i];
  if ( digit % 2 === 0 ) {
    optimalEven = i;
    if ( digit < swapOdd ) {
      break;
    }
  }
};
if ( typeof optimalEven !== "undefined" ) {
  n[ n.length - 1 ] = n[ optimalEven ];
  n[ optimalEven ] = swapOdd;
  answer = n.join( "" );
}
print( answer );

var x = readline();

var last = x[x.length - 1];
var lastEven, swap, res;
for(var i = 0; i < x.length; i++){
    if(x[i] % 2 == 0){
        lastEven = i;
        if (x[i] < last){
            res = x.slice(0, i) + last + x.slice(i + 1, -1) + x[i];
            break;
        }
    }
}

if (res){
    print(res);
}
else{
    if(lastEven != undefined){
        res = x.slice(0, lastEven) + last + x.slice(lastEven + 1, -1) + x[lastEven];
        print(res);
    }
    else{
        print(-1);
    }
}

const mainFunction = (lines) => {
    let n = lines[0].split("")
    for (let i = 0; i < n.length - 1; i++) {
        if (+n[i] % 2 === 0 && +n[n.length - 1] > +n[i]) {
            [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]
            console.log(n.join(""))
            return 0
        }
    }
    for (let i = 0; i < n.length - 1; i++) {
        if (+n[i] % 2 === 0 && +n[n.length - 1] < +n[i]) {
            [n[i], n[n.length - 1]] = [n[n.length - 1], n[i]]
            console.log(n.join(""))
            return 0
        }
    }
    console.log(-1)
}

const { EOL } = require('os')
if (__filename.substr(9, 4) != "azer") {
    let yourInputData = ''
    process.stdin.on('data', i => yourInputData += i)
    process.stdin.on('end', () => mainFunction(yourInputData.split(EOL)))
} else {
    const fileSystem = require("fs");
    mainFunction(fileSystem.readFileSync('input.txt', 'utf8').split(EOL))
}

var input = readline();
var indexToSwapWith = -1;
var inputLength = input.length;
for (var i =0; i< inputLength; i++) {
	if(input [i] % 2 === 0 ) {
		indexToSwapWith = i;
		if(input[i] < input[inputLength - 1]) {
			break;
		}
	}
}
var temp = input[indexToSwapWith]
print(replaceChars(replaceChars(input, indexToSwapWith, input[inputLength - 1]), inputLength -1, temp));

function replaceChars (input, index, newValue) {
    return input.substring(0, index) + newValue + input.substring(index + 1);
}

(function() {

var s = readline().split("");

var r = -1;
var l = -1;
var z = +s[s.length-1];
for(var i = 0; i < s.length; i++) {
    var v = +s[i];
    if(v%2==0) {
        if(v<z && l==-1) l=i;
        if(v>z) r = i;
    }
}

if(r==-1 && l==-1) return print()-1;
var ind = r==-1?l:r;
s[s.length-1] = s[ind];
s[ind] = z;
print(s.join());

})();

(function() {

var s = readline().split("");

for(var i = 0; i < s.length; i++) {
    if(parseInt(s[i])%2==0 && parseInt(s[i])>parseInt(s[s.length-1])) {
        var t = s[s.length-1];
        s[s.length-1] = s[i];
        s[i] = t;
        return print(s.join(""));
    }
}
print(-1);

})();

var s = readline().split("");

for(var i = 0; i < s.length; i++) {
    if(parseInt(s[i])%2==0) {
        var t = s[s.length-1];
        s[s.length-1] = s[i];
        s[i] = t;
        print(s.join(""));
    }
}
print(-1);

(function() {

var s = readline().split("");

for(var i = 0; i < s.length; i++) {
    if(parseInt(s[i])%2==0) {
        var t = s[s.length-1];
        s[s.length-1] = s[i];
        s[i] = t;
        return print(s.join(""));
    }
}
print(-1);

})();

(function() {

var s = readline().split("");

var r = -1;
var l = -1;
var z = +s[s.length-1];
for(var i = 0; i < s.length; i++) {
    var v = +s[i];
    if(v%2==0) {
        if(v<z && l==-1) l=i;
        if(v>z) r = i;
    }
}

if(r==-1 && l==-1) return print()-1;
var ind = r==-1?l:r;
s[s.length-1] = s[ind];
s[ind] = z;
print(s.join(""));

})();

(function() {

var s = readline().split("");

for(var i = 0; i < s.length; i++) {
    if(parseInt(s[i])%2==0 && parseInt(s[i])<parseInt(s[s.length-1])) {
        var t = s[s.length-1];
        s[s.length-1] = s[i];
        s[i] = t;
        return print(s.join(""));
    }
}
print(-1);

})();

(function() {

var s = readline().split("");

var r = -1;
var l = -1;
var z = +s[s.length-1];
for(var i = 0; i < s.length; i++) {
    var v = +s[i];
    if(v%2==0) {
        if(v<z && l==-1) l=i;
        if(v>z) r = i;
    }
}

if(r==-1 && l==-1) return print(-1);
var ind = r==-1?l:r;
s[s.length-1] = s[ind];
s[ind] = z;
print(s.join(""));

})();

var n = readline().split( "" ).map( digit => parseInt( digit, 10 ) );
var evens = n.filter( digit => digit % 2 === 0 );
var answer = -1;
if ( evens.length ) {
  var minEven = Math.min( ...evens );
  var oddToSwap = n[ n.length - 1 ];
  var minEvenToSwapIndex;
  if ( oddToSwap > minEven ) {
    // To maximaze result swap leftmost occurence of minEven.
    minEvenToSwapIndex = n.indexOf( minEven );
  } else {
    // To maximize result swap rightmost occurence of minEven.
    minEvenToSwapIndex = n.lastIndexOf( minEven );
  }
  n[ n.length - 1 ] = minEven;
  n[ minEvenToSwapIndex ] = oddToSwap;
  answer = n.join( "" );
}
print( answer );

var n = readline().split( "" ).map( digit => parseInt( digit, 10 ) );
var answer = -1;
var optimalEven;
var swapOdd = n[ n.length - 1 ];
for ( var i = 0, digit; digit = n[ i ]; ++i ) {
  if ( digit % 2 === 0 ) {
    if ( digit < swapOdd || i === n.length - 2 ) {
      optimalEven = i;
      break;
    }
  }
};
if ( typeof optimalEven !== "undefined" ) {
  n[ n.length - 1 ] = n[ optimalEven ];
  n[ optimalEven ] = swapOdd;
  answer = n.join( "" );
}
print( answer );

var n = readline().split( "" ).map( digit => parseInt( digit, 10 ) );
var minEven = Math.min( ...n.filter( digit => digit % 2 === 0 ) );
var swapOdd = n[ n.length - 1 ];
if ( swapOdd > minEven ) {
  // To maximaze result swap leftmost occurence of minEven.
  n[ n.indexOf( minEven ) ] = swapOdd;
} else {
  // To maximize result swap rightmost occurence of minEven.
  n[ n.lastIndexOf( minEven ) ] = swapOdd;
}
n[ n.length - 1 ] = minEven;
print( n.join( "" ) );

var n = readline().split( "" ).map( digit => parseInt( digit, 10 ) );
var answer = -1;
var optimalEven;
var swapOdd = n[ n.length - 1 ];
for ( var i = 0, digit; digit = n[ i ]; ++i ) {
  if ( digit % 2 === 0 ) {
    optimalEven = i
    if ( digit < swapOdd ) {
      break;
    }
  }
};
if ( typeof optimalEven !== "undefined" ) {
  n[ n.length - 1 ] = n[ optimalEven ];
  n[ optimalEven ] = swapOdd;
  answer = n.join( "" );
}
print( answer );


You are given two strings $$$s$$$ and $$$t$$$, both of length $$$n$$$. Each character in both string is 'a', 'b' or 'c'.In one move, you can perform one of the following actions:   choose an occurrence of "ab" in $$$s$$$ and replace it with "ba";  choose an occurrence of "bc" in $$$s$$$ and replace it with "cb". You are allowed to perform an arbitrary amount of moves (possibly, zero). Can you change string $$$s$$$ to make it equal to string $$$t$$$?

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$s$$$ and $$$t$$$. The second line contains string $$$s$$$ of length $$$n$$$. Each character is 'a', 'b' or 'c'. The third line contains string $$$t$$$ of length $$$n$$$. Each character is 'a', 'b' or 'c'. The sum of $$$n$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase, print "YES" if you can change string $$$s$$$ to make it equal to string $$$t$$$ by performing an arbitrary amount of moves (possibly, zero). Otherwise, print "NO".

5

3

cab

cab

1

a

b

6

abbabc

bbaacb

10

bcaabababc

cbbababaac

2

ba

ab

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let n = readline();
    let s = readline();
    let t = readline();
    if (Stringo(s, t)) print("YES");
    else print("NO");
  }
}
function Stringo(s, t) {
  let i = 0;
  let j = 0;
  while (i < s.length || j < t.length) {
    while (s[i] == "b") i++;
    while (t[j] == "b") j++;
    if ((i == s.length || j == s.length) && i != j) return false;
    if (s[i] !== t[j]) return false;
    if (s[i] == "a" && i > j) return false;
    if (s[i] == "c" && i < j) return false;
    i++;
    j++;
  }
  return true;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let n = readNum();
    let s = readLine();
    let t = readLine();
    let res = true;
    let v1 = [], v2 = [];
    for (let i = 0; i < s.length; i++) {
        if (s[i] !== "b") {
            v1.push([i, s[i]])
        }
        if (t[i] !== "b") {
            v2.push([i, t[i]])
        }
    }
    if (v1.length != v2.length) {
        res = false;
    } else {
        for (let i = 0; i < v1.length; i++) {
            if (v1[i][1] == v2[i][1] && v1[i][1] == "a" && v1[i][0] > v2[i][0]) {
                res = false;
            }
            if (v1[i][1] == v2[i][1] && v1[i][1] == "c" && v1[i][0] < v2[i][0]) {
                res = false;
            }else if(v1[i][1] != v2[i][1]){
                res = false;
            }
        }
    }

    return res ? "YES" : "NO";
}
function rearArr() {
    return readLine().split(" ");
}
function readNum() {
    return parseInt(readLine());
}

'use strict';

async function solve(n, a, b) {
  let sa = 0,
      sb = 0,
      sc = 0,
      sa1 = 0,
      sb1 = 0,
      sc1 = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] === 'a') sa++;else if (a[i] === 'b') sb++;else sc++;
    if (b[i] === 'a') sa1++;else if (b[i] === 'b') sb1++;else sc1++;
    if (sc > sc1 || sa1 > sa) return 'NO';
  }
  if (sa !== sa1 || sb !== sb1 || sc !== sc1) return 'NO';
  {
    let sa = '',
        sb = '';
    for (let ch of a) {
      if (ch !== 'b') sa += ch;
    }
    for (let ch of b) {
      if (ch !== 'b') sb += ch;
    }
    return sa === sb ? 'YES' : 'NO';
  }
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = await read();
      const b = await read();
      res.push(await solve(n, 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);
  console.log(output);
});

'use strict';

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

class INPUT {
	constructor() {
		this.input = '';
		this.curLine = 0;
	}

	append(str) {
		this.input += str;
	}

	prepare() {
		this.input = this.input.split('\n').map((str) => str.trim());
	}

	readLine() {
		return this.input[this.curLine++];
	}

	readInts() {
		return this.readLine()
			.split(' ')
			.map((x) => parseInt(x, 10));
	}
}

const input = new INPUT();

process.stdin.on('data', (str) => {
	input.append(str);
});

process.stdin.on('end', () => {
	input.prepare();
	main();
});

function solve() {
	const [n] = input.readInts();
	let a = input.readLine();
	let b = input.readLine();

	const L = [];
	const R = [];
	const M = [];
	let p = 0;

	for (let i = 0; i < n; i++) {
		if (a[i] === 'c') {
			p = i + 1;
		} else if (a[i] === 'b') {
			L.push(p);
		}
	}

	p = n - 1;

	for (let i = n - 1; i >= 0; i--) {
		if (a[i] === 'a') {
			p = i - 1;
		} else if (a[i] === 'b') {
			R.push(p);
		}
	}

	R.reverse();

	for (let i = 0; i < n; i++) {
		if (b[i] === 'b') {
			M.push(i);
		}
	}

	// console.log('L', L);
	// console.log('M', M);
	// console.log('R', R);

	p = 0;

	if (M.length != L.length) {
		console.log('NO');
		return;
	}

	for (let i = 0; i < M.length; i++) {
		while (p < L.length && M[i] < L[p]) {
			p++;
		}

		if (p == L.length || M[i] > R[p]) {
			console.log('NO');
			return;
		}

		p++;
	}

	if (
		a
			.split('')
			.filter((x) => x != 'b')
			.join('') !=
		b
			.split('')
			.filter((x) => x != 'b')
			.join('')
	) {
		console.log('NO');
		return;
	}

	console.log('YES');
}

function main() {
	let [T] = input.readInts();

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

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let n = readline();
    let s = readline();
    let t = readline();
    if (Stringo(s, t)) print("YES");
    else print("NO");
  }
}
function Stringo(s, t) {
  let i = 0;
  let j = 0;
  while (i < s.length && j < t.length) {
    while (s[i] == "b") i++;
    while (t[j] == "b") j++;
    if ((i == s.length || j == s.length) && i != j) return false;
    if (s[i] !== t[j]) return false;
    if (s[i] == "a" && i > j) return false;
    if (s[i] == "c" && i < j) return false;
    i++;
    j++;
  }
  return true;
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    readline();
    let s = readline();
    let t = readline();
    if (Stringo(s, t, 0)) print("YES");
    else print("NO");
  }
}

function Stringo(s, t) {
  let i = 0;
  let j = 0;
  while (i < s.length && j < t.length) {
    while (s[i] == "b") i++;
    while (t[j] == "b") j++;
    if (s[i] !== t[j]) return false;
    if (s[i] == "a" && i > j) return false;
    if (s[i] == "c" && i < j) return false;
    i++;
    j++;
  }
  return true;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let n = readNum();
    let s = readLine();
    let t = readLine();
    let res = true;
    let v1 = [], v2 = [];
    for (let i = 0; i < s.length; i++) {
        if (s[i] !== "b") {
            v1.push([i, s[i]])
        }
        if (t[i] !== "b") {
            v2.push([i, t[i]])
        }
    }
    if (v1.length != v2.length) {
        res = false;
    } else {
        for (let i = 0; i < v1.length; i++) {
            if (v1[i][1] == v2[i][1] && v1[i][1] == "a" && v1[i][0] > v2[i][0]) {
                res = false;
                break;
            }
            if (v1[i][1] == v2[i][1] && v1[i][1] == "c" && v1[i][0] < v2[i][0]) {
                res = false;
                break;
            }
        }
    }

    return res ? "YES" : "NO";
}
function rearArr() {
    return readLine().split(" ");
}
function readNum() {
    return parseInt(readLine());
}

'use strict';

async function solve(n, a, b) {
  let sa = 0,
      sb = 0,
      sc = 0,
      sa1 = 0,
      sb1 = 0,
      sc1 = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] === 'a') sa++;else if (a[i] === 'b') sb++;else sc++;
    if (b[i] === 'a') sa1++;else if (b[i] === 'b') sb1++;else sc1++;
    if (sc > sc1 || sa1 > sa) return 'NO';
  }
  if (sa !== sa1 || sb !== sb1 || sc !== sc1) return 'NO';
  return 'YES';
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = await read();
      const b = await read();
      res.push(await solve(n, 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);
  console.log(output);
});