let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const rows = lines.slice(1)

  rows.forEach(r => console.log(isFinite(r.split(/\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a === 1
}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const t = Number(lines[0])

  for(let i = 1; i <= t; i++) {
    const r = lines[i].split(/\s/).map(Number).sort((a, b) => b - a)

    console.log(isFinite(r))
  }
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a === 1 ? 'Finite' : 'Infinite'
}

  var lines = parseInt(readline(), 10);

  function gcd(a, b) {
    while (true) {
      if (b === 0) return a;
      a %= b;
      if (a === 0) return b;
      b %= a;
    }
  }

  for (var i = 0; i < lines; i++) {
    var ab = readline()
      .split(" ")
      .map(function(value) {
        return parseInt(value);
      })
      .sort();

    print(gcd(ab[0], ab[1]) > 1 ? "Infinite" : "Finite");
  }

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const rows = lines.slice(1)

  rows.forEach(r => console.log(isFinite(r.split(/\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a !== 1
}


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 = () => BigInt(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const max = (a, b) => a > b ? a : b;

function main () {
	let T = rn();
	while (T--) {
		let n = rn();

		const ans = max(6n, n + 1n) / 2n * 5n;

		console.log(ans.toString());
	}
}

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 = () => BigInt(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let n = rn();

		if (n < 6) n = 6n;
		if (n&1n) n++;

		console.log((n*5n/2n).toString());
	}
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = BigInt(lines[l++])
        // var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n).toString())
    }
});

function solve(n) {
    // 6 8 10
    // 15 20 25
    if (n < 6n) {
        return 15n
    }
    if (n & 1n) {
        return solve(n + 1n)
    }
    const r = n % 6n
    const k = (n - r) / 6n
    if (r === 0n) {
        return k * 15n
    } else if (r === 2n) {
        return (k - 1n) * 15n + 20n
    } else if (r === 4n) {
        return (k - 1n) * 15n + 25n
    }
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const n = this.lines[this.lineIndex]
    return (this.lineIndex += 1), n
  }
  readIntegersOfLine() {
    const n = this.readLine().match(integerRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  readNumsOfLine() {
    const n = this.readLine().match(decimalRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  print(n) {
    stdout.write(n)
  }
  async init() {
    const n = await this.readLines()
    this.lines = n
  }
  readLines() {
    const n = []
    return new Promise(e => {
      stdin.on('data', e => n.push(e)),
        stdin.on('end', function () {
          const t = n.join('').split(os.EOL)
          e(t)
        })
    })
  }
}
async function __main__(n) {
  const e = new InputAndOutput()
  await e.init(), n(e)
}
function solve(n) {
  if (n <= 6n) return 15n
  if (n <= 8n) return 20n
  if (n <= 10n) return 25n
  return (5n * (n % 2n === 1n ? n + 1n : n)) / 2n
}
__main__(function (n) {
  const e = Number(n.readLine())
  for (let t = 1; t <= e; ++t) {
    const e = solve(BigInt(n.readLine()))
    n.print(e + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  if (e <= 6) return 15n
  if (e <= 8) return 20n
  if (e <= 10) return 25n
  let n = BigInt(e)
  return n % 2n === 1n && (n += 1n), (5n * n) / 2n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  return e <= 6
    ? 15
    : e <= 8
    ? 20
    : e <= 10
    ? 25
    : 1 & e
    ? (5 * (e + 1)) / 2
    : (5 * e) / 2
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  const n = Math.floor(e / 120),
    t = e - 120 * n,
    s = 12 * n * 25,
    i = t % 6,
    r = t % 8,
    o = t % 10
  return 0 === i || 0 === r || 0 === o
    ? s + ((5 * t) >> 1)
    : i >= r && i >= o
    ? s + 15 * Math.ceil(t / 6)
    : r >= i && r >= o
    ? s + 20 * Math.floor(t / 8) + (r <= 6 ? 15 : 20)
    : s + 25 * Math.floor(t / 10) + (o <= 6 ? 15 : o <= 8 ? 20 : 25)
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})


const { EOL } = require('os')

const solution = (startTemperature, customers) => {
    let time = 0
    const possibleRange = [
        startTemperature,
        startTemperature,
    ]

    let good = true

    for (const [ arrivalTime, low, high ] of customers) {
        if (good) {
            const elapsed = arrivalTime - time
            possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)
            possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)

            if (possibleRange[1] < possibleRange[0]) {
                good = false
            }

            time = arrivalTime
        }
    }

    return good
}

let input = ''

let m = 0
const readline = () => {
    return input[m++]
}

const readNumbers = () => readline().split(' ').map(Number)

const onEnd = () => {
    input = input.split(EOL)

    const [ inputCount ] = readNumbers()

    for (let i = 0; i < inputCount; i++) {
        const [ customerCount, startTemperature ] = readNumbers()
        const customers = (function * () {
            for (let j = 0; j < customerCount; j++) {
                yield readNumbers()
            }
        }())
        if (solution(startTemperature, customers)) {
            console.log('yes')
        } else {
            console.log('no')
        }

        while (!customers.next().done) {}
    }
}

process.stdin.on('data', c => input += c)
process.stdin.on('end', onEnd)

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 vis = new Array(n)
    for(let i = 0; i < n; i ++) {
      vis[i] = readInts(input, ptr++)
    }

    vis.sort((a, b) => a[0] - b[0])

    let li = m
    let hi = m
    let curr = 0
    let f = true
    for(let i = 0; i < n; i ++) {
      const [ti, l, h] = vis[i]
      let diff = ti - curr
      let changed = false
      if(l >= hi) {
        if(diff + hi >= l) {
          changed = true
          li = l
          hi = Math.min(hi + diff, h)
        }
      }
      else if(h <= li) {
        if(li - diff <= h) {
          changed = true
          hi = h
          li = Math.max(li - diff, l)
        }
      }
      else if(l >= li && h <= hi) {
        changed = true
        li = l
        hi = h
      }
      else if(l <= li && h <= hi) {
        changed = true
        li = Math.max(li - diff, l)
        hi = h
      }
      else if(l >= li && h >= hi) {
        changed = true
        li = l
        hi = Math.min(hi + diff, h)
      }
      else if(l <= li && h >= hi) {
        changed = true
        li = Math.max(li - diff, l)
        hi = Math.min(hi + diff, h)
      }

      // console.log(l, h, li, hi, diff)
      if(!changed) {
        wr('NO')
        f = false
        break
      }
      curr = ti
    }

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

var q = parseInt(readline())

while(q--)
{
    var input = readline().split(" ").map(function(x) { return parseInt(x); });
    var n = input[0];
    var m = input[1];

    var ct = 0;
    var cl = m;
    var ch = m;
    var can = 'YES';
    while(n--)
    {
        input = readline().split(" ").map(function(x) { return parseInt(x); });
        var t = input[0];
        var l = input[1];
        var h = input[2];

        var delT = t - ct;
        var ct = t;
        var cl = Math.max(cl - delT, l);
        var ch = Math.min(ch + delT, h);

        if (cl > ch)
        {
            can = 'NO';
        }
    }
    print(can);
}

const { EOL } = require('os')

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const lines = input.split(EOL) /*your input text, split by lines*/
    console.log(lines);
})

input = input.split(EOL)

let i = 0
const readline = () => {
    return input[i++]
}

const solution = (startTemperature, customers) => {
    console.log('startTemperature', startTemperature, 'customers', customers)
    let time = 0
    const possibleRange = [
        startTemperature,
        startTemperature,
    ]

    for (const [ arrivalTime, low, high ] of customers) {
        console.log([ arrivalTime, low, high ])
        const elapsed = arrivalTime - time
        possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)
        possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)

        if (possibleRange[1] < possibleRange[0]) {
            return false
        }

        time = arrivalTime
    }

    return true
}

const readNumbers = () => readline().split(' ').map(Number)

console.log('start')

console.log('typeof readline', typeof readline)

const inputCount = readNumbers()

console.log('inputCount', inputCount)

for (let i = 0; i < inputCount; i++) {
    const [ customerCount, startTemperature ] = readNumbers()
    const customers = (function * () {
        for (let j = 0; j < customerCount; j++) {
            yield readNumbers()
        }
    }())
    if (solution(startTemperature, customers)) {
        console.log('yes')
    } else {
        console.log('no')
    }
}


var repeatTimes = readline();

while (repeatTimes--) {
    var sum = 0;
    var res = 0;
    var a = readline().split(' ').map(Number);
    var n = a[0], B = a[1], x = a[2], y = a[3];

    while(n) {
        sum += sum + x <= B ? x : -y;
        res += sum;
        n--;
    }

    print(res);
}

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline().split(' ').map(Number);
  var n = a[0];
  var B = a[1], x = a[2], y = a[3];
  var sum = 0;
  var ans = 0;

  while(n > 0) {
    sum += sum + x <= B ? x : -y;
    ans += sum;
    n--;
  }
  print(ans);
}

'use strict'; /*jslint node:true, browser:true, es6:true*/
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}
const EPS = 1e-6;

function sum(n, B, x, y){
  let sum = 0;
  let a = 0;
  for (let i=0; i<n; i++){
    if (a+x<=B)
      a = a+x;
    else
      a = a-y;
    sum += a;
  }
  return sum;
}

function main() {
    let T = +readline();
    while (T--){
      let [n, B, x, y] = readline().split(' ').map(a=>+a);
      print(sum(n, B, x, y))
    }
}

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

/***
Educational Codeforces Round 125 (Div. 2)
2022-03-22

B. XY Sequence
***/

function main() {
  // INPUT: Number of test cases
  let t = readline();
  t = parseInt(t);
  let s;
  for (let i = 0; i < t; i++) {
    // INPUT: 'n B x y'
    // n (int 1..2e5) : length of Sequence
    // b (int 1..1e10) : max of any element
    // x (int 1..1e10) : a' = a+x possible
    // y (int 1..1e10) : a' = a+y possible
    s = readline();
    s = s.split(' ');
    const n = parseInt(s[0]);
    const b = parseInt(s[1]);
    const x = parseInt(s[2]);
    const y = parseInt(s[3]);

    // we might want to think of the problem as a linear combination
    // fx-gy where f+g = 1+2+3+...+(n-1) = n(n-1)/2

    // x and y are positive so we can subtract all the y's first
    // and then add the x's (so don't worry about going over)

    // we might be able to greed x until you can't add any more x's
    // (we want as many x's as we can early on)

    let a = 0;
    let sum = 0;
    for (let j = 0; j < n; j++) {
      if (a + x <= b) {
        a = a + x;
      } else {
        a = a - y;
      }
      sum += a;
    }
    console.log(sum);
  }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        var n = a[0], b = a[1], x = a[2], y = a[3];
        var ans = 0;
        var e = 0;
        for(j = 0; j < n; j++){
            if(e + x <= b){
                e += x;
            }else{
                e -= y;
            }
            ans += e;
        }
        console.log(ans);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let [n, B, x, y] = readline().split(' ').map(Number);
        let sum = 0;
        let curr = 0;

        for (let i = 1; i <= n; i++) {
            let lg = curr + x;
            let sm = curr - y;
            if (lg > B) curr = sm; else curr = lg;
            sum += curr;
        }

        output(sum);
    }
}

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, b, x, y] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, b, x, y)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, b, x, y) {
    let now = 0
    let ans = 0
    for (let i = 1; i <= n; i++) {
        if (now + x <= b && now + x - y <= b) {
            now += x
        } else {
            now -= y
        }
        ans += now
        // console.log(now)
    }
    return ans
}

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline().split(' ').map(Number);
  var x = a[0];
  var y = a[1];

  if (x === 0 && y === 0) {
    print(0);
    continue;
  }

  var z = Math.sqrt(x * x + y * y);

  var r = Math.round(z);
  if (Math.abs(z - r) < 0.000001) {
    print(1);
    continue;
  }

  print(2);
}

'use strict'; /*jslint node:true, browser:true, es6:true*/
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}
const EPS = 1e-6;

function sum(n, B, x, y){
  let sum = 0;
  let a = 0;
  for (let i=0; i<n; i++){
    if (a+x<=B)
      a = a+x;
    else
      a = a-y;
    sum += a;
  }
  return sum;
}

function main() {
    let T = +readline()[0];
    while (T--){
      let [n, B, x, y] = readline().split(' ').map(a=>+a);
      print(sum(n, B, x, y))
    }
}


function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = +$()
  while (t--) {
    let n = +$(), s = $(), ne = Arr(n, i => i + 1);
    let res = 0, i = 0, j = 0;
    while (i < n) {
      res++;
      while (j < n && s[j] != s[ne[j]]) j = ne[j];
      if (j < n) {
        ne[j] = ne[ne[j]];
      } else {
        i = ne[i];
      }
      while (i < n && s[i] == s[ne[i]]) i = ne[i];
      if (i >= n) break;
      i = ne[i];
      if (j < i) j = i;
      // log(res, i, j)
    }
    log(res)
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
        operations++;
        spare += strain - 2;
        if (waitForSalvation < spare) {
          operations += waitForSalvation;
          spare = 0;
          waitForSalvation = 0;
        } else {
          operations += spare;
          waitForSalvation -= spare;
          spare = 0;
        }
      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }

  if (strain > 1) {
    operations++;

    spare += strain - 2;
    if (waitForSalvation < spare) {
      operations += waitForSalvation;
      spare = 0;
      waitForSalvation = 0;
    } else {
      operations += spare;
      waitForSalvation -= spare;
      spare = 0;
    }
  } else {
    waitForSalvation++;
  }

  // if (spare >= waitForSalvation) {
  //   operations += waitForSalvation;
  // } else {
  //   operations += spare;
  //   waitForSalvation -= spare;
  operations += Math.ceil(waitForSalvation / 2);
  //}
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = +$()
  while (t--) {
    let n = +$(), s = $()
    let res = 0, i = 0, j = n - 1
    while (i <= j) {
      res++;
      if (s[i] == s[i + 1]) {
        while (s[i] == s[i + 1]) i++;
        i++;
      } else {
        i++;
        j--;
      }
      // log(res, i, j)
    }
    log(res)
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          spare+=strain-2;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          waitForSalvation++;
          strain=1;
          currBit = binString[j];
      }
    }
  }
  if (strain > 1) {
    operations++;
    spare+=strain-2;
    currBit = binString[j];
    strain=1;
}
else
{
    waitForSalvation++;
}

if(spare>=waitForSalvation)
{
    operations+=waitForSalvation;
}
else
{
    operations+=spare;
    waitForSalvation-=spare;
    operations+=Math.ceil(waitForSalvation/2);
}
//   if(!blank)
//   {
//       operations++;
//   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {

      if (strain > 1) {
        operations++;
        if(!initialStrain)
        {
            spare += strain - 2;
        }
        else
        {
            initialStrain = false;
        }

      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;
    if(!initialStrain)
        {
            spare += strain - 2;
        }
        else
        {
            initialStrain = false;
        }
  } else {
    operations++;
  }

  if (spare >= waitForSalvation) {
    operations += waitForSalvation;
  } else {
    operations += spare;
    waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  }
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit;
  var operations = 0;
  var blank = true;
  for (var j = 0; j < length; j++) {
    if (blank) {
      strain=1
      currBit = binString[j];
      blank=false;
      continue;
    }

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          operations++;
          blank = true;
      }
    }
  }

  if(!blank)
  {
      operations++;
  }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          spare+=strain-2;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          waitForSalvation++;
          strain=0;
          currBit = binString[j];
      }
    }
  }
  if (strain > 1) {
    operations++;
    spare+=strain-2;
    currBit = binString[j];
    strain=1;
}
else
{
    waitForSalvation++;
}

if(spare>=waitForSalvation)
{
    operations+=waitForSalvation;
}
else
{
    operations+=spare;
    waitForSalvation-=spare;
    operations+=Math.ceil(waitForSalvation/2);
}
//   if(!blank)
//   {
//       operations++;
//   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {

      if (strain > 1) {
        operations++;

            spare += strain - 2;
        if(waitForSalvation<spare)
        {
          operations+=waitForSalvation;
          spare=0;
        }
        else
        {
          operations += spare;
          waitForSalvation-=spare;
          spare = 0;
        }
        // else
        // {
        //     initialStrain = false;
        // }

      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;

            spare += strain - 2;
            if(waitForSalvation<spare)
        {
          operations+=waitForSalvation;
          spare=0;
        }
        else
        {
          operations += spare;
          waitForSalvation-=spare;
          spare = 0;
        }

  } else {
    waitForSalvation++;
  }

  // if (spare >= waitForSalvation) {
  //   operations += waitForSalvation;
  // } else {
  //   operations += spare;
  //   waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  //}
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
        operations++;
        spare += strain - 2;
      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;
    spare += strain - 2;
  } else {
    operations++;
  }

  if (spare >= waitForSalvation) {
    operations += waitForSalvation;
  } else {
    operations += spare;
    waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  }
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}


var test = readline(), x, b;
while(test--) {
  x = readline();
  b = x - 1;
  print('1 ' + b);
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
// your code goes here
var arr = '';
process.stdin.on('data',function(chunk){
    arr+=chunk;
    arr = arr.split('\r\n');
    let ncase= arr.length - 1;
    let x = 1;
    while(x<ncase){
        console.log(arr[x]-1,1);
        x++;
    }
});

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const x = readInt()
    wr(x - 1 + " " + 1)
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
  	var x = nextInt();
  	output[i] = "1 " + (x - 1);
  }
  myout(myconv(output, 9));
}

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

let c = 0;

const gcd = (a, b) => {
  while (b !== 0) {
    const t = b;
    b = a % b;
    a = t;
  }

  return a;
};

const lcm = (a, b) => {
  return (a * b) / gcd(a, b);
};

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

  const n = +d;
  console.log(1, n - 1);

  c++;
});

let data = '';
process.stdin.on('data', c => data += c);

const sol = () => {
     nums = data.trim().split(/\n/g).map(Number);
     nums.shift();
     result = nums.map((e) => {
          return `1 ${e-1}`;
     });
     console.log(result.join('\n'));
}

process.stdin.on('end', sol);

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const x = getInt()
    print(1, x - 1)
  }
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var num = +readline();
    print(`${num - 1} ${1}`);
  }
}
main()

var t = parseInt(readline());
while(t-- > 0){
    var n = parseInt(readline());
    print(`1 ${n-1}`);
}

var test = readline(), x;
while(test--) {
  x = readline();
  print('1 ' + (x - 1));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let times = readline();
    while (times--) {
        let input = parseInt(readline());
        output(input - 1, 1);
    }

}
function output(...ans) {
    console.log(ans.join(' '));
}

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.split('\n'); main(); })
const readline = () => { return inputString[currentLine++] }

function main() {
    let n = parseInt(readline());
    for (let i = 0; i < n; i++) {
        const number = parseInt(readline());
        console.log(`1 ${number - 1}`);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
// your code goes here
var arr = '';
process.stdin.on('data',function(chunk){
    arr+=chunk;
    arr = arr.split('\r\n');
    let ncase= arr.length - 1;
    let x = 1;
    while(x<=ncase){
        console.log(arr[x]-1,1);
        x++;
    }
});


var firstLayout = readline()
var secondLayout = readline()

var input = readline();
var output = '';

for (var i = 0; i < input.length; i++) {
  var char = input[i];

  if (~'0123456789'.indexOf(char)) {
    output += char;
    continue;
  }

  if (char === char.toUpperCase()) {
    var LayoutCharPos = firstLayout.indexOf(char.toLowerCase());
    output += secondLayout[LayoutCharPos].toUpperCase();
  } else {
    var LayoutCharPos = firstLayout.indexOf(char);
    output += secondLayout[LayoutCharPos];
  }
}

print(output);

var k1 = readline();
var k2 = readline();
var inp = readline();

var i = 0, j = 0, z = 0, l = inp.length, out = "";

for(i = 0; i< l; i++)
{
  // ������� �����
  if(inp.charCodeAt(i) >= 65 && inp.charCodeAt(i) <= 90)
  {
    z = inp.charCodeAt(i)+32;
    for(j = 0; j< 26; j++)
    {
      if(k1.charCodeAt(j) == z)
      {
        out = out + k2[j].toUpperCase();
      }
    }
  }
  else if(inp.charCodeAt(i) >= 97 && inp.charCodeAt(i) <= 122)
  // ��������� �����
  {
    for(j = 0; j< 26; j++)
    {
      z = inp.charCodeAt(i);
      if(k1.charCodeAt(j) == z)
      {
        out = out + k2[j];
      }
    }

  }
  // ��� ���������
  else
  {
    out = out + inp[i];
  }
}

print(out);

var from = readline().split('')
var to = readline().split('')
var convert = readline().split('')
print(convert.map(x => !isNaN(x) ? x : to[from.indexOf(x)] || to[from.indexOf(x.toLowerCase())].toUpperCase() ).join(''))

var layout1 = readline();
var layout2 = readline();
var input = readline();

var output = '';
for(var i=0; i<input.length; i++){
	if(isNaN(input[i])){
		var isLower = (input[i]+'').toLowerCase()==(input[i]+'');
		var char = isLower?(input[i]+''):(input[i]+'').toLowerCase();
		output+=isLower?layout2[layout1.indexOf(char)]:layout2[layout1.indexOf(char)].toUpperCase();
	}else{
		output+=input[i];
	}
}
write(output);

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

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

  if (c === 1) {
    l2 = d;
    c++;
    return;
  }

  const text = d;
  let ans = '';
  const obj = {};

  for (let i = 0; i < l1.length; i++) {
    obj[l1[i]] = l2[i];
    obj[l1[i].toUpperCase()] = l2[i].toUpperCase();
  }

  for (let i = 0; i < text.length; i++) {
    if (obj[text[i]]) {
      ans += obj[text[i]];
    }
    else {
      ans += text[i];
    }
  }

  // for (let i = 0; i < text.length; i++) {
  //   const idx = l1.indexOf(text[i]);
  //   const idxLower = l1.indexOf(text[i].toLowerCase());

  //   if (idx !== -1) {
  //     ans += l2[idx];
  //   }
  //   else if (idxLower !== -1) {
  //     ans += l2[idxLower].toUpperCase();
  //   }
  //   else {
  //     ans += text[i];
  //   }
  // }

  console.log(ans);

  c++;
});

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

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

  if (c === 1) {
    l2 = d;
    c++;
    return;
  }

  const text = d;
  let ans = '';

  for (let i = 0; i < text.length; i++) {
    const idx = l1.indexOf(text[i]);
    const idxLower = l1.indexOf(text[i].toLowerCase());

    if (idx !== -1) {
      ans += l2[idx];
    }
    else if (idxLower !== -1) {
      ans += l2[idxLower].toUpperCase();
    }
    else {
      ans += text[i];
    }
  }

  console.log(ans);

  c++;
});

    var recorder = readline(),
        derecorder = readline(),
        record = readline(),
        result = '';

    for (var i = 0; i < record.length; i++){
        var number = recorder.indexOf(record[i]);
        var numberUpper = recorder.indexOf(record[i].toLowerCase());
        if (number >= 0 ){
            result += derecorder[number];
        } else if(numberUpper >= 0){
            result += derecorder[numberUpper].toUpperCase();
        } else if (!isNaN(parseInt(record[i]))){
            result += record[i];
        }
    }

print(result);

alph1 = readline();
alph2 = readline();
s = readline();
s1 = '';
for(var i=0; i< s.length; i++) {
    var char = s[i];
    if (/[0-9]/.test(char)) {
        s1 = s1 + char;
        continue;
    }
    var lowChar = s[i].toLowerCase();
    var resChar = alph2[alph1.indexOf(lowChar)];
    if (char != lowChar) {
        resChar = resChar.toUpperCase();
    }
    s1 = s1 + resChar;
}

print(s1);

var fr = readline().split('')
var to = readline().split('')
var convert = readline().split('')
write(convert.map(x => !isNaN(x) ? x : to[fr.indexOf(x)] || to[fr.indexOf(x.toLowerCase())].toUpperCase()).join(''))

(function main(){
  //http://codeforces.com/problemset/problem/831/B
  var layout1Minusculas = readline();
  var layout1Mayusculas = layout1Minusculas.toUpperCase();
  var layout2Minusculas = readline();
  var layout2Mayusculas = layout2Minusculas.toUpperCase();
  var datos = readline();

  var salida = "";
  for (var i = 0; i < datos.length; i++) {
    if(!isNaN((datos[i]))){
      salida += datos[i];
    }else if(caracterEsMayuscula(i)){
      traducir(i, layout1Mayusculas, layout2Mayusculas);
    }else{
      traducir(i, layout1Minusculas, layout2Minusculas);
    }
  }

  function caracterEsMayuscula(index){
    var charcode = datos.charCodeAt(index);
    return  charcode >= 65 && charcode <= 90;
  }

  function traducir(index, layoutInicial, layoutFinal){
    var indexLayout = layoutInicial.indexOf(datos[i]);
    salida += layoutFinal.charAt(indexLayout);
  }

  print(salida);
})();

function derecording(record, recorder, derecorder){
    var result = '';

    for (var i = 0; i < record.length; i++){
        var number = recorder.indexOf(record[i]);
        var numberUpper = recorder.indexOf(record[i].toLowerCase());
        if (number >= 0 ){
            result += derecorder[number];
        } else if(numberUpper >= 0){
            result += derecorder[numberUpper].toUpperCase();
        } else if (!isNaN(parseInt(record[i]))){
            result += record[i];
        }
    }

    return result;
}


'use strict';

const a = readline();
const n = a.length;

const ans = new Array(n).fill(0);

for (let i = 1; i < n; i++) {
    if (a[i] == 'a') {
        ans[i - 1] = 1 - ans[i - 1];
        ans[i] = 1 - ans[i];
    }
}

print(ans.join(' '));

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input= '', cin, cout;

process.stdin.on('data', function(chunk) {
    input+=chunk;

});

process.stdin.on('end', function() {
    input = input.split('\n');
    cout = function(data) {process.stdout.write(data+'\n')};
    var inputLineIndex = 0;
    cin = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
    process.exit(main() || 0);
});

function main() {
    function swap(line, i) {
        return line.substr(0, i+1).split("").reverse().join("") + line.substr(i+1);
    }

    let line = cin().replace(/\r?\n/g, "").trim();
    let ans = '';

    for (let i = 0; i < line.length; i++) {
        if (line[0] === 'b') {
            if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {
                ans += '1 ';
                line = swap(line, i);
            } else {
                ans += '0 ';
            }
        } else {
            if (line[i] === 'b' && line[i+1] === 'a') {
                ans += '1 ';
                line = swap(line, i);
            } else if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {
                ans += '1 ';
                line = swap(line, i);
            } else {
                ans += '0 ';
            }
        }
    }

    cout(ans.trim());
    //cout(line);

    return 0;
}

const readline = require('readline')

const interface = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
})

let smallest = [0]
let largest = [0]
interface.on('line', line => {
  for (let i = 1; i < line.length; i++) {
    if (line[i] == 'a') {
      smallest = largest.concat(1)
      largest = largest.concat(0)
    } else if(line[i] == 'b'){
      largest = smallest.concat(1)
      smallest = smallest.concat(0)
    }
  }
  ouputSolution(smallest)
})

function ouputSolution (list) {
  let str = ''
  for (let i = 0; i < list.length; i++) {
    str += list[i] + ' '
  }
  console.log(str)
}

'use strict';

const a = readline();
const n = a.length;

const ans = new Array(n).fill(0);

for (let i = 1; i < n; i++) {
    if (a[i] == 'a') {
        ans[i - 1] = 1 - ans[i - 1];
    }
}

ans[n - 1] = 1;

print(ans.join(' '));


var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		const mp = new Map();
		for (let i = 0; i < 2*n; i++) {
			mp.set(a[i], [mp.has(a[i]) ? mp.get(a[i])[0] + 1 : 1, 0]);
		}

		function use (k) {
			if (mp.has(k)) {
				const [cnt, curcnt] = mp.get(k);
				if (curcnt < cnt) {
					mp.set(k, [cnt, curcnt + 1]);
					return true;
				}
			}
			return false;
		}

		function resetMap() {
			for (const [ky, [cnt, curcnt]] of mp.entries()) {
				mp.set(ky, [cnt, 0]);
			}
		}

		let ans, ansx;
		for (let i = 0; i < 2*n - 1; i++) {
			resetMap();
			use(a[i]);
			curx = a[2*n - 1];
			ok = true;
			ans = [[a[i], a[2*n - 1]]];
			for (let j = 2*n - 2; j >= 0; j--) {
				if (j != i) {
					const [cnt, curcnt] = mp.get(a[j]);
					if (cnt == curcnt) {
						continue;
					}

					use(a[j]);
					if (use(curx - a[j])) {
						ans.push([a[j], curx - a[j]]);
						curx = Math.max(a[j], curx - a[j]);
					} else {
						ok = false;
						break;
					}
				}
			}
			if (ok) {
				ansx = a[2*n-1] + a[i];
				break;
			}
		}

		if (ansx) {
			console.log('YES\n', ansx);
			for (const row of ans)
				console.log(row.join(' '));
		} else {
			console.log('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--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		const mp = new Map();
		for (let i = 0; i < 2*n; i++) {
			const [cnt, usecnt] = mp.has(a[i]) ? mp.get(a[i]) : [0, 0];
			mp.set(a[i], [cnt + 1, usecnt]);
		}

		function use (k) {
			if (mp.has(k)) {
				const [cnt, usecnt] = mp.get(k);
				if (usecnt < cnt) {
					mp.set(k, [cnt, usecnt + 1]);
					return true;
				}
			}
			return false;
		}

		function resetMap () {
			for (const [ky, [cnt, usecnt]] of mp.entries()) {
				mp.set(ky, [cnt, 0]);
			}
		}

		let ans = [];
		for (let i = 0; !ans.length && i < 2*n - 1; i++) {
			resetMap();
			let curx = a[2*n - 1] + a[i];
			for (let j = 2*n - 1; j >= 0; j--) {
				const [cnt, usecnt] = mp.get(a[j]);
				if (cnt == usecnt) {
					continue;
				}

				use(a[j]);
				if (use(curx - a[j])) {
					ans.push([a[j], curx - a[j]]);
					curx = Math.max(a[j], curx - a[j]);
				} else {
					ans = [];
					break;
				}
			}
		}

		if (ans.length) {
			console.log('YES\n', ans[0][0] + ans[0][1]);
			for (const row of ans)
				console.log(row.join(' '));
		} else {
			console.log('NO');
		}
	}
}

'use strict';

function solve(n, a) {
  a.sort((a, b) => b - a);
  next: for (let skip = 1; skip < 2 * n; skip++) {
    const res = [];
    res.push([a[0]]);
    const vis = new Set([0]);
    let sum = a[0];
    const map = new Map();
    for (let [i, num] of a.entries()) {
      if (i === 0 || i === skip) continue;
      if (!map.has(num)) map.set(num, []);
      map.get(num).push(i);
    }
    for (let i = 1; i < 2 * n; i++) {
      if (vis.has(i) || skip === i) continue;
      const x = a[i],
            y = sum - x;
      const b = map.get(y);
      if (!b || !b.length || b.length === 1 && b[0] === i) continue next;
      let j = b.pop();
      if (j === i) j = b.pop();
      vis.add(i);
      vis.add(j);
      res.push([a[i], y]);
      sum = x;
    }
    for (let i = 0; i < 2 * n; i++) {
      if (!vis.has(i)) res[0].push(a[i]);
    }
    return `YES\n${res[0][0] + res[0][1]}\n` + res.map(arr => arr.join(' ')).join('\n');
  }
  return 'NO';
}

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

function solve(n, a) {
  a.sort((a, b) => b - a);
  const nums = new Map([...new Set(a)].sort((a, b) => a - b).map((num, i) => [num, i]));
  const N = nums.size;
  const g = Array.from({
    length: N
  }, () => []);
  for (let i = 0; i < 2 * n; i++) {
    for (let j = i + 1; j < 2 * n; j++) {
      const sum = a[i] + a[j];
      if (nums.has(sum)) {
        g[nums.get(sum)].push([i, j]);
      }
    }
  }
  let res = [];
  const dfs = (sum = a[0], vis = new Set([0]), path = [[0]]) => {
    if (vis.size === 2 * n - 1) {
      res = [...path];
      return true;
    }
    for (let [i, j] of g[nums.get(sum)]) {
      if (vis.has(i) || vis.has(j)) continue;
      vis.add(i);
      vis.add(j);
      path.push([i, j]);
      let res = false;
      if (a[i] > a[j]) {
        res = dfs(a[i], vis, path);
      } else {
        res = dfs(a[j], vis, path);
      }
      vis.delete(i);
      vis.delete(j);
      path.pop();
      if (res) return true;
    }
    return false;
  };
  if (dfs()) {
    let vis = [];
    for (let [i, j] of res) {
      vis[i] = 1;
      vis[j] = 1;
    }
    for (let i = 1; i < 2 * n; i++) {
      if (!vis[i]) {
        res[0].push(i);
        break;
      }
    }
    return 'YES\n' + res.map(arr => arr.map(i => a[i]).join(' ')).join('\n');
  } else {
    return 'NO';
  }
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res.push(await solve(n, a));
    }
    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";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const f="local"===process.argv[2],p=t=>{if(f){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=0;for(let o=0;o<t-1;++o){if(r[o]>r[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;t<o;++t)if(r[t]>e){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(r[o]>r[o+1]&&e>r[o+1])return void i.default.puts(-1)}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, x] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let swaps = 0
//
//   for (let i = 0; i < n - 1; ++i) {
//     if (a[i] > a[i + 1]) {
//       // try to fix
//
//       if (a[i + 1] >= x) {
//         for (let j = 0; j < i; ++j) {
//           if (a[j] > x) {
//             let t = a[j]
//             a[j] = x
//             x = t
//             swaps++
//           }
//         }
//         let t = a[i]
//         a[i] = x
//         x = t
//         swaps++
//       } else {
//         io.puts(-1)
//         return
//       }
//     }
//
//     // io.debug(a)
//
//     if (a[i] > a[i + 1]) {
//       if (x > a[i + 1]) {
//         io.puts(-1)
//         return
//       }
//
//       // let t = a[i + 1]
//       // a[i + 1] = x
//       // x = t
//       // swaps++
//     }
//   }
//
//   io.puts(swaps)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

/*
 * File Created: Monday, 30th November 2020 3:31:00 pm
 * Author: Lukas Rimkus
 */

'use-strict'

const { count } = require("console");

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = data.shift().split(' ').map(Number);

        const arr = data.shift().split(' ').map(Number);

        const res = d(n[0], n[1], arr);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function a(num)
{
    return num.length ;
}

function b(goal)
{

    function jump1(y,k)
    {
        return y + k;
    }
    function jump2(y)
    {
        return y - 1;
    }

    let sum = 0;

    let jumps = 0;

    let arr = [];

    while(sum < goal)
    {
        jumps++;

        arr.push(jumps);

        sum = sum + jumps;
    }

    if(sum === goal)
    {
        return arr.length;
    }
    else
    {
        let current_pos = sum;

        // that's how many steps back;
        let diference = current_pos - goal;

        console.log(arr, arr.length, sum, diference)

        for(let i = 0 ; i < arr.length; i++)
        {
            if((arr[i] + 1) === diference)
            {
                return arr.length;
            }
        }
       return arr.length + 1;
    }
}

function c(x,y)
{
    const arr = new Array(2);

    arr[0] = x - 1;

    arr[1] = y
    return arr;
}

function help(a)
{
    for(let i = 0; i < a.length; i++)
    {
        if(a[i] > a[i + 1])
        {
            return false;
        }
    }
    return true;
}

function d(n, x, arr)
{
    let count = 0 ;

    if(n === 1 || help(arr))
    {
        return 0;
    }

    for(let i = 0 ; i < arr.length; i++)
    {
        const current = arr[i];

        if(current > x)
        {
            [arr[i], x] = [x, arr[i]];

            count++;
        }
        if(help(arr))
        {
            return count;
        }
    }
    return  -1;
}

module.exports = d;

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    let [len, lastItem] = readLine().split(" ").map(Number);
    const arr = readLine().split(" ").map(Number);
    if (isSorted(arr) || len === 1) console.log(0);
    else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const current = arr[i];
        if (current > lastItem) {
          [arr[i], lastItem] = [lastItem, arr[i]];
          count++;
          if (isSorted(arr)) break;
        }
      }
      if (isSorted(arr)) console.log(count);
      else console.log(-1);
    }
    function isSorted(arr) {
      let sorted = true;
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
          sorted = false;
          break;
        }
      }
      return sorted;
    }
  }
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const f="local"===process.argv[2],p=t=>{if(f){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=0;for(let o=0;o<t-1;++o){if(r[o]>r[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;t<o;++t)if(r[t]>e){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(r[o]>r[o+1]){if(e>r[o+1])return void i.default.puts(-1);let t=r[o+1];r[o+1]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, x] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let swaps = 0
//
//   for (let i = 0; i < n - 1; ++i) {
//     if (a[i] > a[i + 1]) {
//       // try to fix
//
//       if (a[i + 1] >= x) {
//         for (let j = 0; j < i; ++j) {
//           if (a[j] > x) {
//             let t = a[j]
//             a[j] = x
//             x = t
//             swaps++
//           }
//         }
//         let t = a[i]
//         a[i] = x
//         x = t
//         swaps++
//       } else {
//         io.puts(-1)
//         return
//       }
//     }
//
//     // io.debug(a)
//
//     if (a[i] > a[i + 1]) {
//       if (x > a[i + 1]) {
//         io.puts(-1)
//         return
//       }
//
//       let t = a[i + 1]
//       a[i + 1] = x
//       x = t
//       swaps++
//     }
//   }
//
//   io.puts(swaps)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, lastItem] = readLine().split(" ").map(Number);
    const arr = readLine().split(" ").map(Number);
    if (isSorted(arr) || len === 1) console.log(0);
    else {
      arr.push(lastItem);
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [last, current] = [arr[len], arr[i]];
        if (current > last) {
          [arr[len], arr[i]] = [current, last];
          count++;
          if (isSorted(arr)) break;
        }
      }
      if (isSorted(arr)) console.log(count);
      else console.log(-1);
    }
    function isSorted(arr) {
      let sorted = true;
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
          sorted = false;
          break;
        }
      }
      return sorted;
    }
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, lastItem] = readLine().split(" ").map(Number);
    const arr = readLine().split(" ").map(Number);
    if (isSorted(arr) || len === 1) console.log(0);
    else {
      arr.push(lastItem);
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [last, current] = [arr[len], arr[i]];
        if (current > last) {
          [arr[len], arr[i]] = [current, last];
          count++;
        }
      }
      if (isSorted(arr)) console.log(count);
      else console.log(-1);
    }
    function isSorted(arr) {
      let sorted = true;
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
          sorted = false;
          break;
        }
      }
      return sorted;
    }
  }
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],f=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:f,runEachTest:t=>{f((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=0;for(let o=0;o<t-1;++o)if(r[o]>r[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;t<o;++t)if(r[t]>e){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, x] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let swaps = 0
//
//   for (let i = 0; i < n - 1; ++i) {
//     if (a[i] > a[i + 1]) {
//       // try to fix
//
//       if (a[i + 1] >= x) {
//         for (let j = 0; j < i; ++j) {
//           if (a[j] > x) {
//             let t = a[j]
//             a[j] = x
//             x = t
//             swaps++
//           }
//         }
//         let t = a[i]
//         a[i] = x
//         x = t
//         swaps++
//       } else {
//         io.puts(-1)
//         return
//       }
//     }
//   }
//
//   io.puts(swaps)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const f="local"===process.argv[2],p=t=>{if(f){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=0;for(let o=0;o<t-1;++o){if(r[o]>r[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;t<o;++t)if(r[t]>e){let i=r[t];r[t]=e,e=i,n++}let t=r[o];r[o]=e,e=t,n++}}if(i.default.debug(r),r[o]>r[o+1]){let t=r[o+1];r[o+1]=e,e=t,n++}}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, x] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let swaps = 0
//
//   for (let i = 0; i < n - 1; ++i) {
//     if (a[i] > a[i + 1]) {
//       // try to fix
//
//       if (a[i + 1] >= x) {
//         for (let j = 0; j < i; ++j) {
//           if (a[j] > x) {
//             let t = a[j]
//             a[j] = x
//             x = t
//             swaps++
//           }
//         }
//         let t = a[i]
//         a[i] = x
//         x = t
//         swaps++
//       } else {
//         io.puts(-1)
//         return
//       }
//     }
//
//     io.debug(a)
//
//     if (a[i] > a[i + 1]) {
//       let t = a[i + 1]
//       a[i + 1] = x
//       x = t
//       swaps++
//     }
//   }
//
//   io.puts(swaps)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const f="local"===process.argv[2],p=t=>{if(f){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function h(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:a,nextNumbers:h,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){f&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=0;for(let o=0;o<t-1;++o)if(r[o]>r[o+1]){if(!(r[o+1]>=e))return void i.default.puts(-1);{for(let t=0;t<o;++t)if(r[t]>e){let i=r[t];r[t]=e,e=i,n++}let t=r[o];if(r[o]=e,e=t,n++,e>r[o+1])return void i.default.puts(-1)}}i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, x] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let swaps = 0
//
//   for (let i = 0; i < n - 1; ++i) {
//     if (a[i] > a[i + 1]) {
//       // try to fix
//
//       if (a[i + 1] >= x) {
//         for (let j = 0; j < i; ++j) {
//           if (a[j] > x) {
//             let t = a[j]
//             a[j] = x
//             x = t
//             swaps++
//           }
//         }
//         let t = a[i]
//         a[i] = x
//         x = t
//         swaps++
//
//         if (x > a[i + 1]) {
//           io.puts(-1)
//           return
//         }
//       } else {
//         io.puts(-1)
//         return
//       }
//     }
//   }
//
//   io.puts(swaps)
// }
//
// io.runEachTest(main)
// // io.runMain(main)