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

})();

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

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


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