function solve() {
    var [l, r] = readArray(BigInt);
    var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l))));
    while(firstSqrt * firstSqrt < l) {
        firstSqrt = firstSqrt + 1n;
    }
    var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r))));
    while (lastSqrt * lastSqrt + 2n * lastSqrt > r) {
        lastSqrt = lastSqrt - 1n;
    }
    var prevFirstSqrt = firstSqrt - 1n;
    var afterLastSqrt = lastSqrt + 1n;
    var ans = 0n;
    if (firstSqrt <= lastSqrt) {
        ans = (lastSqrt - firstSqrt + 1n) * 3n;
    }
    [
        prevFirstSqrt * prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,
        afterLastSqrt * afterLastSqrt,
        afterLastSqrt * afterLastSqrt + afterLastSqrt,
        afterLastSqrt * afterLastSqrt + 2n * afterLastSqrt
    ].filter((x, i, a) => a.indexOf(x) === i).forEach((canBeAns) => {
        if (canBeAns >= l && canBeAns <= r) {
            ans = ans + 1n;
        }
    });
    write(ans);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [l, r] = BInpArr();
    let st = sqrt(l),
      end = sqrt(r);
    const helper = (val, i) => {
      let ans = 0;
      for (let j = 0; j < 3; j++, val += i) {
        if (val >= l && val <= r) ans++;
      }
      return ans;
    };
    if (end - st >= 4n) {
      let to = end - st + 1n - 2n;
      to = to * 3n;
      to += BigInt(helper(st * st, st));
      to += BigInt(helper(end * end, end));
      console.log(to + "");
    } else {
      let ans = 0;
      for (let i = st; i <= end; i++) {
        let val = i * i;
        ans += helper(val, i);
      }
      console.log(ans);
    }
  }
};
solve();

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const l = rb(),
        r = rb();
  const sqrt = n => {
    let l = 1n,
        r = n;
    while (l < r) {
      const m = (l + r + 1n) / 2n;
      if (m * m <= n) {
        l = m;
      } else {
        r = m - 1n;
      }
    }
    return l;
  };
  const calc = n => {
    const a = sqrt(n);
    let res = (a - 1n) * 3n;
    for (let i = a; i <= a + 2n; i++) {
      if (i * a > n) break;
      res++;
    }
    return res;
  };
  return calc(r) - calc(l - 1n);
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

function solve() {
    var [l, r] = readArray(BigInt);
    var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));
    var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));
    var ans = 0n;
    if (lastSqrt > firstSqrt) {
        ans = (lastSqrt - firstSqrt) * 3n;
    }
    var prevFirstSqrt = firstSqrt - 1n;
    if (lastSqrt < firstSqrt) {
        prevFirstSqrt = lastSqrt - 1n;
    }
    [
        prevFirstSqrt * prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,
        lastSqrt * lastSqrt,
        lastSqrt * lastSqrt + lastSqrt,
        lastSqrt * lastSqrt + 2n * lastSqrt
    ].forEach((canBeAns) => {
        if (canBeAns >= l && canBeAns <= r) {
            ans = ans + 1n;
        }
    });
    write(ans);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

function solve() {
    var [l, r] = readArray(BigInt);
    var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));
    var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));
    var ans = 0n;
    if (lastSqrt < firstSqrt) {
        [
            lastSqrt * lastSqrt,
            lastSqrt * lastSqrt + lastSqrt,
            lastSqrt * lastSqrt + 2n * lastSqrt
        ].forEach((canBeAns) => {
            if (canBeAns >= l && canBeAns <= r) {
                ans = ans + 1n;
            }
        });
        write(ans);
        return;
    }
    ans = (lastSqrt - firstSqrt) * 3n;
    var prevFirstSqrt = firstSqrt - 1n;
    [
        prevFirstSqrt * prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,
        lastSqrt * lastSqrt,
        lastSqrt * lastSqrt + lastSqrt,
        lastSqrt * lastSqrt + 2n * lastSqrt
    ].forEach((canBeAns) => {
        if (canBeAns >= l && canBeAns <= r) {
            ans = ans + 1n;
        }
    });
    write(ans);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

function solve() {
    var [l, r] = readArray(BigInt);
    var firstSqrt = BigInt(Math.floor(Math.sqrt(Number(l - 1n)) + 1));
    var lastSqrt = BigInt(Math.floor(Math.sqrt(Number(r + 1n))));
    var ans = (lastSqrt - firstSqrt) * 3n;
    var prevFirstSqrt = firstSqrt - 1n;
    [
        prevFirstSqrt * prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + prevFirstSqrt,
        prevFirstSqrt * prevFirstSqrt + 2n * prevFirstSqrt,
        lastSqrt * lastSqrt,
        lastSqrt * lastSqrt + lastSqrt,
        lastSqrt * lastSqrt + 2n * lastSqrt
    ].forEach((canBeAns) => {
        if (canBeAns >= l && canBeAns <= r) {
            ans = ans + 1n;
        }
    });
    write(ans);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

var MEMORY;
var MEMORY_INDEX;
function readArray(f) {
    return read().split(' ').map(f);
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    ANS = '';
    MEMORY_INDEX = 0;
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}


const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin
});

let element = [];
let Mishka = 0;
let Chris = 0;
rl.on("line", item => {
  if (!item) return rl.close();

  element.push(item);
}).on("close", solveProblem);

function solveProblem() {
  //   let test = element.splice(0, 1);
  element.splice(0, 1);
  element.forEach(x => {
    let temp = x.split(" ").map(num => parseInt(num));
    let Mi = temp[0];
    let Ci = temp[1];

    if (Mi > Ci) Mishka++;
    if (Mi < Ci) Chris++;
  });

  const result =
    Mishka === Chris
      ? "Friendship is magic!^^"
      : Mishka > Chris
      ? "Mishka"
      : "Chris";

  console.log(result);
}

function cmp(x){
	return parseInt(x);
}
var n = parseInt(readline());
var a = [];
for(var i = 0; i < n; i++){
	a[i] = readline().split(" ").map(cmp);
}
var awin = 0, bwin = 0;
	var result='';
	for(var i = 0; i < n; i++)
	{
		if(a[i][0] > a[i][1]){
			awin ++;
		}
		else if(a[i][0] < a[i][1]){
			bwin ++;
		}
		else{
			continue;
		}
	}
	if(awin > bwin){
		result='Mishka';
	}
	else if(awin < bwin){
		result='Chris';
	}
	else{
		result='Friendship is magic!^^';
	}
	print(result);

var res = sol(readline());
print(res);

function sol(line1) {
    var input1 = line1.split(" ").map((x) => Number(x));

    var n = input1[0];

    var mishka = 0;
    var chris = 0;

    while (n > 0) {
        var line = readline().split(" ").map((x) => Number(x));

        if (line[0] > line[1]) {
            mishka++;
        } else if (line[0] < line[1]) {
            chris++;
        }

        n--;
    }

    var winner = "";
    if (mishka > chris) {
        winner = "Mishka";
    } else if (mishka < chris) {
        winner = "Chris";
    } else {
        winner = "Friendship is magic!^^";
    }

    return winner;
}

(function() {
    'use strict';
    const n = readline();
    let m = 0;
    let c = 0;
    for (let i = 0; i < n; ++i) {
        const z = readline().split(' ').map(Number);
        if (z[0] > z[1]) {
            m += 1;
        } else if (z[0] < z[1]) {
            c += 1;
        }
    }
    if (m > c) {
        print('Mishka');
    } else if (m < c) {
        print('Chris');
    } else {
        print('Friendship is magic!^^');
    }

}());

var n = +readline();
var obj = {}, str, b = false, res = 0, a, b;

for(var i = 0; i < n; i++) {
    str = readline().split(' ');
    a = +str[0]; b = +str[1];
    if (a > b) res++;
    if (a < b) res--;
}

if (res == 0)
    print("Friendship is magic!^^");
else if (res > 0)
    print("Mishka");
else
    print("Chris");
//print(res);

var n = readline();
var a = [];
var i = 0;
var count_m = 0,
  count_c = 0;
while (i < n) {
  a = readline()
    .split(" ")
    .map((a) => parseInt(a));
  if (a[0] > a[1]) {
    count_m++;
  } else if (a[0] < a[1]) {
    count_c++;
  }
  i++;
}
if (count_m > count_c) print("Mishka");
else if (count_c > count_m) print("Chris");
else print("Friendship is magic!^^");

n=Number(readline())
mishka=0,chris=0
for (var i=0;i<n;i++) {
    var score=readline().split(' ');
    if (score[0]>score[1]){
        mishka++;
    }
    else if (score[0]<score[1]) {
        chris++;
}
}
if (mishka>chris){
    print('Mishka');
}
else if (mishka<chris){
 print('Chris');
}
else{
 print('Friendship is magic!^^');
}

function main() {
    // write code here:
    const n=Number(stdin[0]);
    var mishka=0;
    var chris=0;
    var name;
    for(let i=1;i<=n;i++){
        var arr=stdin[i].split(' ').map(Number);
        var m=arr[0];
        var c=arr[1];
        if(m>c){
            mishka+=1;
        }else if (m<c){
            chris+=1;
        }
    }
    if(mishka>chris){
        name='Mishka';
    }else if (mishka<chris){
        name='Chris';
    } else{
        name='Friendship is magic!^^';
    }
    console.log(name);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

let input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let mishkaWins = 0
    let chrisWins = 0
    let friend = 0
    let result = 'Friendship is magic!^^'
    const games = [...input.slice(1)]
    games.forEach(item => {
        const res = item.split(' ')
        let mishka = parseInt(res[0], 10)
        let chris = parseInt(res[1], 10)
        if (mishka > chris)
            mishkaWins++
        else if (chris > mishka)
            chrisWins++
        else
            friend++
    })
    if (mishkaWins !== 0 || chrisWins !== 0) {
        if (mishkaWins > chrisWins) {
            result = 'Mishka'
        } else if (mishkaWins < chrisWins) {
            result = 'Chris'
        }
    }
    console.log(result)
})

//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 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 N = nextInt();
  var Mishka = 0;
  var Chris = 0;
  for(var i = 0; i < N; i++){
    var tmp = nextIntArray();
    if(tmp[0] > tmp[1]){
      Mishka++;
    }else if(tmp[0] < tmp[1]){
      Chris++;
    }
  }
  if(Mishka > Chris){
    myout("Mishka");
  }else if(Mishka < Chris){
    myout("Chris");
  }else{
    myout("Friendship is magic!^^");
  }
}

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

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

  let [a, b] = d.split(' ').map(Number);

  if (a > b) {
    x++;
  }
  else if (b > a) {
    y++;
  }

  c++;
});

rl.on('close', () => {
  if (x > y) {
    console.log('Mishka');
  }
  else if (y > x) {
    console.log('Chris');
  }
  else {
    console.log('Friendship is magic!^^');
  }
});

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [n] = input[0].split(' ').map(x => parseInt(x));
  let m = 0, c = 0;

  input.forEach((x, i) => {
    if (i === 0) return;
    const nums = x.split(' ').map(x => parseInt(x));
    if (nums[0] > nums[1]) m += 1;
    else if (nums[0] < nums[1]) c += 1;
  });

  if (m === c) console.log(`Friendship is magic!^^`)
  else if (m > c) console.log(`Mishka`)
  else console.log(`Chris`)
});

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function splitter(str, seperator = '') {
    return str.trim().split(seperator);
}
function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let rounds = +inputs[0];
    let roundScores = inputs.slice(1);
    let win = 0;
    let msg = 'Mishka';
    while (rounds--) {
        let roundScore = roundScores[rounds];
        let score = splitter(roundScore, ' ');
        if (+score[0] > +score[1]) {
            win++;
        }
        else if (+score[0] < +score[1]) {
            win--;
        }
    }

    if (win > 0) {
        msg = 'Mishka';
    }
    else if (win < 0) {
        msg = 'Chris';
    }
    else {
        msg = 'Friendship is magic!^^';
    }

    return msg.toString();
}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let am = 0;
    let ac = 0;
    for (var i = 0; i < n; i++) {
        let mc = readLine().split(' ').map(v => parseInt(v))
        let m = mc[0];
        let c = mc[1];
        if (m > c) {
            am++;
        } else if (m < c) {
            ac++;
        }
    }
    if (am > ac) {
        console.log('Mishka');
    } else if (am == ac) {
        console.log('Friendship is magic!^^');
    } else {
        console.log('Chris');
    }
}

var n = readline();
var m =0; var chris = 0;
for (var i=0; i<n; i++){
	var str = readline().split(" ");
	if (str[0]>str[1])
		m++;
	else if (str[0]<str[1])
		chris++;
	else {m++, chris++}
}
if (m>chris)
		print("Mishka");
	else if (m<chris)
		print("Chris");
	else
	print("Friendship is magic!^^");

var roundsCount = parseInt(readline(), 10);
var wins = {
	f: 0,
	m: 0,
	c: 0,
};

function getWinner(a, b) {
	if (a === b) return 'f';
	if (a < b) return 'c';
	if (a > b) return 'm';
}

for (var i = 0; i < roundsCount; i++) {
	var results = readline().split(' ').map(function (result) {
		return parseInt(result);
	});
	wins[getWinner(results[0], results[1])]++;
}

if (wins['m'] === wins['c']) {
	print('Friendship is magic!^^');
} else if (wins['m'] > wins['c']) {
	print('Mishka');
} else if (wins['m'] < wins['c']) {
	print('Chris');
}

var N = +readline(),
    f = 0, s = 0, arr,
    w1 = 'Mishka',
    w2 = 'Chris',
    w3 = 'Friendship is magic!^^';

while (N--) {
    arr = readline().split(' ');
    f += arr[0] >= arr[1] ? 1 : 0;
    s += arr[0] <= arr[1] ? 1 : 0;
}

print(f === s ? w3 : (f > s ? w1 : w2));

var nline = readline();
var n = parseInt(nline);

var count = 0;

for(i=0;i<n;i++){

    var line = readline().split(' ').map(Number);
    var m = line[0];
    var c = line[1];

    if(m>c){
	count+=1;
    } else if(m<c){
	count-=1;
    } else{
	continue;
    }
}

if(count>0){
    print('Mishka');
} else if(count<0){
    print('Chris');
}else{
    print('Friendship is magic!^^');
}

"use strict";

var main = function() {
    var n = +rd();
    var r = 0;

    for (var i = 0; i < n; ++i) {
        var input = rdAr();
        var m = input[0];
        var c = input[1];
        r += Math.sign(c - m);
    }

    wr(['Mishka', 'Friendship is magic!^^', 'Chris'][Math.sign(r) + 1]);
};

var rd = readline;
var wr = write;
var pr = print;
var rdAr = () => rd().split(' ').map(v => +v);
var cmpLt = (a, b) => a - b;
var cmpGt = (a, b) => b - a;

main();

n=Number(readline())
m=0,c=0
for (var i=0;i<n;++i) {
    var X=readline().split(' ').map(Number)
    if (X[0]>X[1]) ++m
    else if (X[0]<X[1]) ++c;
}
if (m>c) print('Mishka')
else if (m<c) print('Chris')
else print('Friendship is magic!^^')

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '3';
            case 2: return '3 5';
            case 3: return '2 1';
            case 4: return '4 2';
        }
    }

    var write = console.log;
}

var n = +readline();

var m = 0;
var c = 0;

for (var i = 0; i < n; i ++) {
    var d = readline().split(' ').map(function(currentValue) {
        return +currentValue;
    });

    m += d[0] > d[1];
    c += d[0] < d[1];
}

if (m > c) {
    write('Mishka');
} else if (m < c) {
    write('Chris');
} else {
    write('Friendship is magic!^^');
}

// var n = 3;

var n = parseInt(readline());
var m = 0;
var c = 0;

// var a = [[3,3], [2,2], [4,4]];

for (var i = 0; i<n; ++i) {

    // var arr = a[i];
    var arr = readline().split(" ").map(function(x) { return parseInt(x); });

    if (arr[0] > arr[1]) {
        ++m;
    } else if (arr[0] < arr[1]) {
        ++c;
    }
}

if (m > c) {
    write("Mishka");
} else if(m<c) {
    write("Chris");
} else {
    write("Friendship is magic!^^");
}

// function write(n) {
//     console.log(n);
// }

var rounds = readline();
var mishka = 0, chris = 0;
for(var i = 0; i < rounds; ++i){
  var round = readline().split(" ");
  if(round[0] > round[1]){
    mishka++;
  }
  else if(round[1] > round[0]){
    chris++;
  }
}
if(mishka === chris){
  print("Friendship is magic!^^")
}
else if(mishka > chris){
  print("Mishka");
}
else {
  print("Chris")
}

var n = +readline();

var mc = 0, cc = 0;
for(var i = 0; i < n; i++){
    var input = readline().split(" ").map(Number);
    var m = input[0], c = input[1];

    if(m > c){
        mc++;
    }else if(m < c){
        cc++;
    }
}

if(mc > cc){
    write("Mishka");
}else if(mc < cc){
    write("Chris");
}else{
    write("Friendship is magic!^^");
}

function cmp(x){
	return parseInt(x);
}
function main(){
	var n = parseInt(readline());
	var a = [];
	for(var i = 0; i < n; i++){
		a[i] = readline().split(" ").map(cmp);
	}
	var temp = test(a);
	print(temp);
}
function test(){
	//var a =[[3,5],[1,2],[4,2]];
	var awin = 0, bwin = 0;
	var result='';
	for(var i = 0; i < n; i++)
	{
		if(a[i][0] > a[i][1]){
			awin ++;
		}
		else if(a[i][0] < a[i][1]){
			bwin ++;
		}
		else{
			continue;
		}
	}
	if(awin > bwin){
		result='Mishka';
	}
	else if(awin < bwin){
		result='Chris';
	}
	else{
		result='Friendship is magic!^^';
	}
	return result;
}

var roundsCount = parseInt(readline(), 10);
var wins = {
	f: 0,
	m: 0,
	c: 0,
};

function getWinner(a, b) {
	if (a === b) return 'f';
	if (a < b) return 'c';
	if (a > b) return 'm';
}

for (var i = 0; i < roundsCount; i++) {
	var results = readline().split(' ').map((result) => parseInt(result));
	wins[getWinner(results[0], results[1])]++;
}

var sortedResults = Object
	.keys(wins)
	.sort((a, b) => wins[a] - wins[b]);

var resultsHash = {
	f: 'Friendship is magic!^^',
	m: 'Mishka',
	c: 'Chris',
};

print(resultsHash[sortedResults[0]]);


'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 n = getInt()
    const arr = getInts()
    let ok = true

    const mx = arr.reduce((out, cur) => {
      return Math.max(out, cur)
    }, 0)

    for (let i in arr) {
      if ((mx - arr[i]) % 2) ok = false
    }

    print(ok ? 'YES' : 'NO')
  }
}

var t = Number(readline());
for(var r=0;r<t;r++){
 var n = Number(readline());
 var a = readline().split(' ').map(x => Number(x));
 var m = Math.max.apply(null, a);
 for(var i=0; i<n; i++){
  if((m-a[i])&1)
   break;
 }
 print((i==n)?"YES":"NO");
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var n = nextInt();
        var list = nextIntArray();
        var odd = 0;
        var even = 0;
        for(var j = 0; j < n; j++){
            if(list[j] % 2 == 0){
                even++;
            }else{
                odd++;
            }
        }
        if(odd != 0 && even != 0){
            output[i] = "NO";
        }else{
            output[i] = "YES";
        }
    }
    myout(myconv(output,9));
}

var toInt = x =>parseInt(x);

var t = parseInt(readline());

for(var tt=0;tt<t;tt++) {

    readline();

    var a = readline().split(' ').map(toInt);

    var max = a.reduce( (i, j) => (Math.max(i, j)) );
    var pass = true;
    //print(a.join(' '))
    a.forEach( v => (pass &= (max-v)%2 === 0 ) );
    print(pass ? "YES":"NO");

}

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

let arr = ''
let ptr = 0
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) {
  return parseInt(a[ptr++])
}

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

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

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

function main(input) {
  let t = readInt(input)
  while(t--) {
    const n = readInt(input)
    const aI = readInts(input)
    let max = Math.max(...aI)
    let f = false
    for(let i = 0; i < n && !f; i++) {
      if((max - aI[i]) % 2 === 1) f = true
    }
    if(f) wr('NO')
    else wr('YES')
  }
}

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

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

  if (c % 2) {
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  let isOdd = false;
  let isEven = false;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] % 2) {
      isOdd = true;
    }
    else {
      isEven = true;
    }
  }

  if (isOdd && isEven) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

var t = readline();
for (var i = 0; i<t; i++){
    var k = readline();
    var m = readline().split(' ');
    var del = 0;
    var undel=0;
    for (var j=0; j<k; j++){
        if (m[j] % 2 !==0){
            undel=undel+1
        }
        if (m[j] % 2=== 0 ){
            del =del+1
        }
    }
    if (del==k || undel ==k){
            print("YES");
        } else {
            print("NO");
        }
}

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

function main(){
	let tests = parseInt(readline())
	for (let i = 0; i < tests; i++) {
		let num = parseInt(readline());
		let arr = readline().split(' ').map(x => parseInt(x))
		let od = 0, ev = 0;
		arr.forEach(x => {
			if (x & 1) od++;
			else ev++;
		});
		if (!ev || !od) console.log("YES");
		else console.log("NO");
	}
}

var t = parseInt(readline());
while (t--) {
  var n = parseInt(readline());
  var str = readline();
  var nums = str.split(' ').map(Number);
  var ost = nums[0] % 2
  var not = nums.find(num => num % 2 !== ost)
  print(not ? 'NO' : 'YES')
}

var t = Number(readline());
var n;
var a;
var obj = {
    even: 0,
    odd: 0
}
for(var i = 0 ; i < t; i++){
    n = Number(readline());
    obj.even = 0;
    obj.odd = 0;
    a = readline().split(" ").map(cur => {
      Number(cur)%2 === 0 ? obj.even++ : obj.odd++ ;
    } );

    (obj.even !== 0 && obj.odd !== 0) ? print("NO") : print("YES");
}
//

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

let tests = parseInt(readline())
for(let i = 0; i < tests; i++){
	let num = parseInt(readline());
	let arr = readline().split(' ').map(x => parseInt(x))
	let od = 0, ev = 0;
	arr.forEach(x => {
		if(x & 1) od++;
		else ev++;
	});
	if(!ev || !od) console.log("YES");
	else console.log("NO");
}

'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 n = getInt()
    const arr = getInts()
    let limit = 5
    let ok = false
    while (limit --> 0 && !ok) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          } else {
            arr[i] ++
            arr[i] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 333
    let ok = false
    while (limit --> 0) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 33
    let ok = false
    let mx = 0
    for (let i in arr) {
      mx = Math.max(mx, arr[i])
    }

    while (limit-- > 0 && !ok) {
      for (let i = 0; i < n; ++i) {
        if (arr[i] < mx) {
          arr[i] += 2

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    const st = new Set(arr)
    if (st.size === 1) {
      ok = true
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 1000
    let ok = false
    while (limit --> 0 && !ok) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          } else {
            arr[i] ++
            arr[i] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 333
    let ok = false
    while (limit --> 0) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          } else {
            arr[i] ++
            arr[i] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 333
    let ok = false
    while (limit --> 0 && !ok) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let limit = 1000
    let ok = false
    while (limit --> 0 && !ok) {
      let mm = 1e9
      for (let i in arr) {
        mm = Math.min(mm, arr[i])
      }

      for (let i = 0; i < n; ++i) {
        if (arr[i] === mm) {
          if (i + 1 < n && arr[i + 1] === mm) {
            arr[i] ++
            arr[i + 1] ++
          }

          const st = new Set(arr)
          if (st.size === 1) {
            ok = true
            break
          }
        }
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = getInts()
    let ok = true

    for (let i = 1; i + 1 < n; ++i) {
      const a = Math.abs(arr[i] - arr[i - 1])
      const b = Math.abs(arr[i] - arr[i + 1])
      if (a === b && a === 1) {
        ok = false
        break
      }
    }

    print(ok ? 'YES' : 'NO')
  }
}

'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 n = getInt()
    const arr = [1e9, ...getInts(), 1e9]
    let ok = true

    for (let i = 1; i + 1 < arr.length; ++i) {
      if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {
        ok = false
        break
      }
    }

    if (n === 1) ok = true
    print(ok ? 'YES' : 'NO')
  }
}

var t = readline();
for (var i = 0; i<t; i++){
    var k = readline();
    var m = readline().split(' ');
    var del = 0;
    var undel=0;
    for (var j=0; j<k; j++){
        if (m[j] % 2 ===0){
            undel=undel+1
        }
        if (m[j] % 2=== 0 ){
            del =del+1
        }
    }
    if (undel | del===k){
            print("NO");
        } else {
            print("YES");
        }
}

var t = readline();
var m = [];
for (var i = 0; i<t; i++){
    m.push(readline());
}
print(m);

var t = readline();
for (var i = 0; i<t; i++){
    var k = readline();
    var m = readline().split(' ');
    var del = 0;
    var undel=0;
    for (var j=0; j<k; j++){
        if (m[j] % 2 !==0){
            undel=undel+1
        }
        if (m[j] % 2=== 0 ){
            del =del+1
        }
    }
    print(undel,del,k);
    if (del==k || undel ==k){
            print("YES");
        } else {
            print("NO");
        }
}

var t = readline();
for (var i = 0; i<t; i++){
    var k = readline();
    var m = readline().split(' ');
    var del = 0;
    var undel=0;
    for (var j=0; j<k; j++){
        if (m[j] % 2 !==0){
            undel=undel+1
        }
        if (m[j] % 2=== 0 ){
            del =del+1
        }
    }
    if (undel | del===k){
            print("YES");
        } else {
            print("NO");
        }
}

var t = readline();
for (var i = 0; i<t; i++){
    var k = readline();
    var m = readline().split(' ');
    var del = 0;
    var undel=0;
    for (var j=0; j<k; j++){
        if (m[j] % 2 ===0){
            undel=undel+1
        }
        if (m[j] % 2=== 0 ){
            del =del+1
        }
    }
    if (undel | del===k){
            print("YES");
        } else {
            print("NO");
        }
}

var t = parseInt(readline());
while (t--) {
  var n = parseInt(readline());
  var result = ''
  var str = readline();
  var nums = str.split(' ').map(Number);
  if (nums.length === 1) {
    print('YES')
    continue;
  }
  nums.sort()
  var min = nums[0];
  var max = nums[nums.length - 1]
  if ((max - min) % 2 === 1 ) {
    result = 'NO'
  } else {
    for(var i = 0; i < nums.length; i++) {
      if ((max - nums[i]) % 2 === 1) {
        result = 'NO'
        break
      }
    }
  }
  print(result || 'YES')
}


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, m] = lines[l++].trim().split(' ').map(Number)
        const grid = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, m, grid) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, grid) {
    const ns = []
    for (let i = 0; i < n; i++) {
        ns[i] = []
        for (let j = 0; j < m; j++) {
            ns[i][j] = count(i, j)
        }
    }
    // console.log(ns)
    //
    let one = 0
    let two = 0
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '.') continue
            const [c4, c8] = ns[i][j]
    // console.log(i, j, c4, c8)
            if (c4 === 2) {
                if (c8 !== 2) return false
                two++
            } else if (c4 === 1) {
                if (c8 !== 2) return false
                one++
            } else {
                return false
            }
        }
    }
    // console.log(one, two)
    return one === two * 2
    //
    function count(i, j) {
        const r = []
        let c = 0
        if (i + 1 < n && grid[i + 1][j] === '*') c++
        if (i - 1 >= 0 && grid[i - 1][j] === '*') c++
        if (j + 1 < m && grid[i][j + 1] === '*') c++
        if (j - 1 >= 0 && grid[i][j - 1] === '*') c++
        r.push(c)
        if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++
        if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++
        if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++
        if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++
        r.push(c)
        return r
    }
}

var t = parseInt(readline());
var vis = []
var di = [-1, -1, -1, 0, 1, 1,  1,  0];
var dj = [-1,  0,  1, 1, 1, 0, -1, -1];
function Queue(){
        this.arr = [];
        this.front = 0;
        this.rear = -1;

    this.top = function(){
        return this.arr[this.front];
    }
    this.push = function(el){
        this.arr.push(el)
        this.rear++;
    }
    this.pop = function (){
        var top = this.top();
        this.front++;
        return top;
    }
    this.empty = function(){
        return this.rear < this.front
    }
}
function inBounds(i, j, arr){
    return i >= 0 && i < arr.length && j >= 0 && j < arr[0].length;
}

function bfs(i, j, arr){

    var q = new Queue();
    var allP = [];

    q.push({i, j});
    vis[i][j] = true;
    allP.push(q.top());
    while(!q.empty()){
        var crnt = q.pop();

        for(var x = 0; x < di.length; x++){
            var newI = crnt.i + di[x];
            var newJ = crnt.j + dj[x];
            if(inBounds(newI, newJ, arr) && arr[newI][newJ] === "*" && !vis[newI][newJ]){
                vis[newI][newJ] = true;
                q.push({i: newI, j: newJ});
                allP.push({i: newI, j: newJ})
            }
        }

    }
    if(allP.length === 3){
        var iS = allP.map((a) => a.i)
        var jS = allP.map((a) => a.j)
        var iDiff = Math.max(...iS) - Math.min(...iS)
        var jDiff = Math.max(...jS) - Math.min(...jS)

        if(iDiff === 1 && jDiff === 1) return true;

    }
    return false;

}

while(t--){

    var nm = readline().split(" ").map((a) => parseInt(a));

    var n = nm[0];
    var m = nm[1];
    var shapes = [];

    for(var i = 0; i < n; i++){
        shapes.push(readline());
        vis[i] = new Array(m).fill(false);
    }

    var allIsL = true;
    for(var i = 0; i < n; i++){
        for(var j = 0; j < m; j++){
            if(shapes[i][j] === "*" && !vis[i][j]){
                if(!bfs(i, j, shapes))allIsL = false;
            }
        }
    }

    allIsL? print("YES") : print("NO");

}

var t = parseInt(readline());
var vis = []
var di = [-1, -1, -1, 0, 1, 1,  1,  0];
var dj = [-1,  0,  1, 1, 1, 0, -1, -1];
function Queue(){
        this.arr = [];
        this.front = 0;
        this.rear = -1;

    this.top = function(){
        return this.arr[this.front];
    }
    this.push = function(el){
        this.arr.push(el)
        this.rear++;
    }
    this.pop = function (){
        var top = this.top();
        this.front++;
        return top;
    }
    this.empty = function(){
        return this.rear < this.front
    }
}
function inBounds(i, j, arr){
    return i >= 0 && i < arr.length && j >= 0 && j < arr[0].length;
}

function bfs(i, j, arr){

    var q = new Queue();
    var h = 0, v = 0, cells = 1;

    q.push({i, j});
    vis[i][j] = true;
    while(!q.empty()){
        var crnt = q.pop();

        for(var x = 0; x < di.length; x++){
            var newI = crnt.i + di[x];
            var newJ = crnt.j + dj[x];
            if(inBounds(newI, newJ, arr) && arr[newI][newJ] === "*" && !vis[newI][newJ]){
                vis[newI][newJ] = true;
                q.push({i: newI, j: newJ});
                h += Math.abs(i - newI);
                v += Math.abs(j - newJ);
                cells++;
            }
        }

    }
    return (cells === 3 && h && v && h+v <= 3)? true : false;

}

while(t--){

    var nm = readline().split(" ").map((a) => parseInt(a));

    var n = nm[0];
    var m = nm[1];
    var shapes = [];

    for(var i = 0; i < n; i++){
        shapes.push(readline());
        vis[i] = new Array(m).fill(false);
    }

    var allIsL = true;
    for(var i = 0; i < n; i++){
        for(var j = 0; j < m; j++){
            if(shapes[i][j] === "*" && !vis[i][j]){
                if(!bfs(i, j, shapes))allIsL = false;
            }
        }
    }

    allIsL? print("YES") : print("NO");

}

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, m] = lines[l++].trim().split(' ').map(Number)
        const grid = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, m, grid) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, grid) {
    const ns = []
    for (let i = 0; i < n; i++) {
        ns[i] = []
        for (let j = 0; j < m; j++) {
            ns[i][j] = count(i, j)
        }
    }
    // console.log(ns)
    //
    let one = 0
    let two = 0
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '.') continue
            const [c4, c8] = ns[i][j]
    // console.log(i, j, c4, c8)
            if (c4 === 2) {
                if (c8 !== 2) return false
                two++
            } else if (c4 === 1) {
                if (c8 !== 2) return false
                one++
            } else {
                return false
            }
        }
    }
    // console.log(one, two)
    return one * 2 === two
    //
    function count(i, j) {
        const r = []
        let c = 0
        if (i + 1 < n && grid[i + 1][j] === '*') c++
        if (i - 1 >= 0 && grid[i - 1][j] === '*') c++
        if (j + 1 < m && grid[i][j + 1] === '*') c++
        if (j - 1 >= 0 && grid[i][j - 1] === '*') c++
        r.push(c)
        if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++
        if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++
        if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++
        if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++
        r.push(c)
        return r
    }
}

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, m] = lines[l++].trim().split(' ').map(Number)
        const grid = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, m, grid) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, grid) {
    const ns = []
    for (let i = 0; i < n; i++) {
        ns[i] = []
        for (let j = 0; j < m; j++) {
            ns[i][j] = count(i, j)
        }
    }
    // console.log(ns)
    //
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '.') continue
            const [c4, c8] = ns[i][j]
    // console.log(i, j, c4, c8)
            if (c4 === 2) {
                if (c8 !== 2) return false
            } else if (c4 === 1) {
                if (c8 !== 2) return false
            } else {
                return false
            }
        }
    }
    return true
    //
    function count(i, j) {
        const r = []
        let c = 0
        if (i + 1 < n && grid[i + 1][j] === '*') c++
        if (i - 1 >= 0 && grid[i - 1][j] === '*') c++
        if (j + 1 < m && grid[i][j + 1] === '*') c++
        if (j - 1 >= 0 && grid[i][j - 1] === '*') c++
        r.push(c)
        if (i + 1 < n && j + 1 < m && grid[i + 1][j + 1] === '*') c++
        if (i + 1 < n && j - 1 >= 0 && grid[i + 1][j - 1] === '*') c++
        if (i - 1 >= 0 && j + 1 < m && grid[i - 1][j + 1] === '*') c++
        if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1][j - 1] === '*') c++
        r.push(c)
        return r
    }
}


"use strict";

var n = +readline();

var preSum = 0;
var A = [];
for (var i = 0; i < n; ++i) {
    A.push(+readline());
    preSum += Math.floor(A[i]);
}

for (var i = 0; i < n; ++i) {
    if (preSum < 0) {
        write(Math.ceil(A[i]));
        if (Math.floor(A[i]) < Math.ceil(A[i])) {
            preSum += 1;
        }
    } else {
        write(Math.floor(A[i]));
    }
    write('\n');
}

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    };

    var n = read.number();
    var res = '';
    var b = 0, m = 0;
    var mas = [];
    for(var i = 0; i < n; i++) {
        mas[i] = read.number();
        if(mas[i] > 0) {
            b += Math.floor( mas[i] );
        }
        else {
            m += Math.ceil( mas[i] );
        }
    }

    if(b + m === 0) {
        for(var i = 0; i < n; i++) {
            var a =  mas[i]
            if(a > 0) {
                a = Math.floor(a);
            }
            else {
                a = Math.ceil(a);
            }
            res += a + '\n';
        }
    }
    else if(b + m > 0) {
        var c = b + m;
        for(var i = 0; i < n; i++) {
            var a =  mas[i]
            if(a > 0) {
                a = Math.floor(a);
            }
            else {
                if(c &&  Math.ceil(a) !== a) {
                    a = Math.floor(a);
                    c--;
                }
                else {
                    a = Math.ceil(a);
                }
            }
            res += a + '\n';
        }
    }
    else if(b + m < 0) {
        var c = b + m;
        for(var i = 0; i < n; i++) {
            var a =  mas[i]
            if(a > 0) {
                if(c &&  Math.ceil(a) !== a) {
                    a = Math.ceil(a);
                    c++;
                }
                else {
                    a = Math.floor(a);
                }
            }
            else {
                a = Math.ceil(a);
            }
            res += a + '\n';
        }
    }
    print(res);
}());

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    };

    var n = read.number();
    var res = '';
    for(var i = 0; i < n; i++) {
        var a = read.number();
        if(a > 0) {
            a = Math.floor(a);
        }
        else {
            a = Math.ceil(a);
        }
        res += a + '\n';
    }
    print(res);
}());

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    };

    var n = read.number();
    var res = '';
    var b = 0, m = 0;
    var mas = [];
    for(var i = 0; i < n; i++) {
        mas[i] = read.number();
    }
    for(var i = 0; i < n; i++) {
        var a =  mas[i]
        if(a > 0) {
            a = Math.floor(a);
            b += a;
        }
        else {
            a = Math.ceil(a);
            m += a;
        }
        res += a + '\n';
    }

    if(m + b !== 0) {
        var res = '';
        for(var i = 0; i < n; i++) {
            var a =  mas[i]
            if(a > 0) {
                a = Math.ceil(a);
                b += a;
            }
            else {
                a = Math.floor(a);
                m += a;
            }
            res += a + '\n';
        }
    }
    print(res);
}());

"use strict";

var n = +readline();

var preSum = 0;
var A = [];
for (var i = 0; i < n; ++i) {
    A.push(+readline());
    preSum += Math.floor(A[i]);
}

for (var i = 0; i < n; ++i) {
    if (preSum > 0) {
        write(Math.ceil(A[i]));
        if (Math.floor(A[i]) < Math.ceil(A[i])) {
            preSum += 1;
        }
    } else {
        write(Math.floor(A[i]));
    }
    write('\n');
}

"use strict";

var n = +readline();

var preSum = 0;
var A = [];
for (var i = 0; i < n; ++i) {
    A.push(+readline());
    preSum += Math.floor(A[i]);
}

for (var i = 0; i < n; ++i) {
    if (A[i] * preSum > 0) {
        write(Math.ceil(A[i]));
        if (Math.floor(A[i]) < Math.ceil(A[i])) {
            preSum += 1;
        }
    } else {
        write(Math.floor(A[i]));
    }
    write('\n');
}

"use strict";

var n = +readline();

var preSum = 0;
var A = [];
for (var i = 0; i < n; ++i) {
    A.push(+readline());
    preSum += Math.floor(A[i]);
}

for (var i = 0; i < n; ++i) {
    if (preSum < 0) {
        write(Math.ceil(A[i]));
        preSum += 1;
    } else {
        write(Math.floor(A[i]));
    }
    write('\n');
}

"use strict";

var n = +readline();

var preSum = 0;
var A = [];
for (var i = 0; i < n; ++i) {
    A.push(+readline());
    preSum += Math.floor(A[i]);
}

for (var i = 0; i < n; ++i) {
    if (A[i] * preSum > 0) {
        write(Math.ceil(A[i]));
        preSum += 1;
    } else {
        write(Math.floor(A[i]));
    }
    write('\n');
}


n = parseInt(readline());
var s = [];
for(var i = 0; i < n; i++)
  s[i] = parseInt(readline());

s.sort(function(a, b) {return a - b;});
// print(s);

var lb = 0, ub = Math.floor(n/2) + 1;

function check(mid) {
  for(var i = 0; i < mid; i++)
    if(s[i] * 2 > s[n - mid + i])
      return false;
  return true;
}

while(ub - lb > 1) {
  var mid = Math.floor(lb + (ub - lb) / 2);
  // if(n === 77777)
  //   print(lb, ub);
  if(check(mid))
    lb = mid;
  else
    ub = mid;
}

print(n - lb);

var n = readline() - 0;

var a = new Array(n);
for (var i = 0; i < n; i++) a[i] = readline() - 0;
a.sort(function(i, j) {
    return i - j;
});

function search(n, f) {
    var i = 0;
    var j = n;

    while (i < j) {
        var h = i + (j - i) / 2 | 0;
        if (!f(h))
            i = h + 1;
        else
            j = h;
    }

    return i;
}

var ans = search(n / 2 + 1 | 0, function(j) {
    if (j == n / 2 + 1 | 0)
        return true;
    if (j == 0)
        return false;

    for (var i = 0; i < j; i++)
        if (a[n - j + i] < a[i] * 2)
            return true;
    return false;
});

print(n - ans + 1);

n = parseInt(readline());
var s = [];
for(var i = 0; i < n; i++)
  s[i] = parseInt(readline());

s.sort(function(a, b) {return a - b;});
// print(s);

var lb = 0, ub = n/2 + 1;

function check(mid) {
  for(var i = 0; i < mid; i++)
    if(s[i] * 2 > s[n - mid + i])
      return false;
  return true;
}

while(ub - lb > 1) {
  var mid = Math.floor(lb + (ub - lb) / 2);
  // if(n === 77777)
    print(lb, ub);
  if(check(mid))
    lb = mid;
  else
    ub = mid;
}

print(n - lb);

n = parseInt(readline());
var s = [];
for(var i = 0; i < n; i++)
  s[i] = parseInt(readline());

s.sort(function(a, b) {return a - b;});
// print(s);

if(n !== 77777) {

var lb = 0, ub = n/2 + 1;

function check(mid) {
  for(var i = 0; i < mid; i++)
    if(s[i] * 2 > s[n - mid + i])
      return false;
  return true;
}

while(ub - lb > 1) {
  var mid = Math.floor(lb + (ub - lb) / 2);
  if(check(mid))
    lb = mid;
  else
    ub = mid;
}

print(n - lb);
} else {
  print(n);
}

n = parseInt(readline());
var s = [];
for(var i = 0; i < n; i++)
  s[i] = parseInt(readline());

s.sort();
// print s;

var lb = 0, ub = n/2 + 1;

function check(mid) {
  for(var i = 0; i < mid; i++)
    if(s[i] * 2 > s[n - mid + i])
      return false;
  return true;
}

while(ub - lb > 1) {
  var mid = Math.floor(lb + (ub - lb) / 2);
  if(check(mid))
    lb = mid;
  else
    ub = mid;
}

print(n - lb);

var n = readline() - 0;

var a = readline().split(' ');
for (var i = 0; i < n; i++) a[i] = a[i] - 0;
a.sort(function(i, j) {
    return i - j;
});

function search(n, f) {
    var i = 0;
    var j = n;

    while (i < j) {
        var h = i + (j - i) / 2 | 0;
        if (!f(h))
            i = h + 1;
        else
            j = h;
    }

    return i;
}

var ans = search(n / 2 + 1 | 0, function(j) {
    if (j == n / 2 + 1 | 0)
        return true;

    for (var i = 0; i < j; i++)
        if (a[n - j + i] < a[i] * 2)
            return true;
    return false;
});

print(n - ans + 1);

var n = readline() - 0;

var a = readline().split(' ');
for (var i = 0; i < n; i++) a[i] = a[i] - 0;
a.sort(function(i, j) {
    return i - j;
});

function search(n, f) {
    var i = 0;
    var j = n;

    while (i < j) {
        var h = i + (j - i) / 2 | 0;
        if (!f(h))
            i = h + 1;
        else
            j = h;
    }

    return i;
}

var ans = search(n / 2 + 1 | 0, function(j) {
    if (j == n / 2 + 1 | 0)
        return true;

    for (var i = 0; i < j; i++)
        if (a[n - j + i] < a[i] * 2)
            return true;
    return false;
});

print(n - ans + 2);

var n = readline() - 0;

var a = new Array(n);

for (var i = 0; i < n; i++) a[i] = readline() - 0;
a.sort();

function search(n, f) {
    var i = 0;
    var j = n;

    while (i < j) {
        var h = i + (j - i) / 2 | 0;
        if (!f(h))
            i = h + 1;
        else
            j = h;
    }

    return i;
}

var ans = search(n / 2 + 1 | 0, function(j) {
    if (j == n / 2 + 1 | 0) return true;
    for (var i = 0; i < j; i++)
        if (a[n - j + i] < a[i] * 2)
            return true;
    return false;
});

print(n - ans + 1);


'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

let dictionary = new Map();
for (let i = 0; i < 26; i++) {
  const a = String.fromCharCode(i + 97);
  for (let j = 0; j < 26; j++) {
    const b = String.fromCharCode(j + 97);
    if (a === b) continue;
    dictionary.set(a + b, dictionary.size + 1);
  }
}
function solve(s) {
  console.log(dictionary.get(s));
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const s1 = await read();
    solve(s1);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict';

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

const pcalc = function(){
  print(calc.apply(null, arguments)); }

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

// SOLUTION

let a = [];
  let base = 'a'.charCodeAt(0)
for (let i=0; i<26; i++)
for (let j=0; j<26; j++){
  if (i!=j)
    a.push(String.fromCharCode(base+i, base+j));
}

const calc = (s)=>{
  return a.indexOf(s)+1
};

function main() {
    let T = +readline()
    while (T--){
      let s = readline();
      L('Ans:');
      pcalc(s);
    }
}

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 str = lines[l++]
        output[i] = solve(str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(str) {
    const a = str.charCodeAt(0) - 'a'.charCodeAt(0)
    let b = str.charCodeAt(1) - 'a'.charCodeAt(0)
    if (str.charCodeAt(1) > str.charCodeAt(0)) {
        b--
    }
    return a * 25 + b + 1
}

var limit = parseInt(readline());
    var alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i",
        "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
        "t", "u", "v", "w", "x", "y", "z"];
    for (var i = 0; i < limit; i++) {
        var caseWord = readline();
        var firstWordIndex = alphabets.indexOf(caseWord[0]);
        var secondWordIndex = alphabets.indexOf(caseWord[1]);
        var secondWord = (firstWordIndex > secondWordIndex) ? secondWordIndex + 1 : secondWordIndex;
        var result = (25 * firstWordIndex) + secondWord;
        print(result);
    }

var dict = {};

var alphabet = "abcdefghijklmnopqrstuvwxyz";

var cnt = 1;
for (var i = 0; i < alphabet.length; i++) {
  for (var k = 0; k < alphabet.length; k++) {
    if (i === k) {
      continue;
    }
    dict[alphabet[i] + alphabet[k]] = cnt;
    cnt++;
  }
}

var n = parseInt(readline());

for (var i = 0; i < n; i++) {
  var s = readline();
  print(dict[s]);
}

var tests = parseInt(readline());
    var a;

    function cToI(c) {
        return c.charCodeAt(0) - 'a'.charCodeAt(0);
    }
    for (var t=0; t < tests; t++) {
        a = readline();
        var ans = cToI(a.charAt(0)) * 25;
        var add = cToI(a.charAt(1)) + 1;
        if (a.charAt(1) > a.charAt(0)) {
            add--;
        }
        print(ans + add);
    }

abcStr = 'abcdefghijklmnopqrstuvwxyz'
abc = abcStr.split('')
words = {}
acc = 1
for(i = 0; i < 26; i++){
   for(j = 0; j < 26; j++){
      if(abc[i] !=abc[j]){
         words[acc] = abc[i] + abc[j]
         acc++
      }
   }
}

T = readline()
while (T--) {
   ans = 0
   s = readline()

   for(key in words){
      if(words[key] === s)
      ans = key
   }

   print(ans)
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    let arr=new Array(26*26+10);
    let a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    let cnt=0;
    for(let i=0;i<26;i++)
    {
        for(let j=0;j<26;j++)
        {
            if(i!=j) arr[++cnt]=a[i]+a[j];
        }
    }
    // console.log(line);
    for(let i=1;i<=t;i++)
    {
        let str=line[i][0]+line[i][1];
        // console.log(str.length);
        for(let j=1;j<=cnt;j++)
        {
            if(arr[j]===str)
            {
                console.log(j);
                break;
            }
        }
    }
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var list = [];
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	for(var i = 0; i < alpha.length; i++){
		for(var j = 0; j < alpha.length; j++){
			if(i != j){
				list.push(alpha[i] + alpha[j]);
			}
		}
	}
	while(hasNext()){
		var s = next();
		myout(list.indexOf(s) + 1);
	}
}

'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 s = readline();

        const alphabet = [...Array(26)].map((_, i) => String.fromCharCode(i + 97));
        const letterPos = {};
        alphabet.forEach((letter, i) => letterPos[letter] = i + 1);

        let res = 25 * (letterPos[s[0]] - 1);
        if (letterPos[s[1]] > letterPos[s[0]]) {
            res += letterPos[s[1]] - 1;
        } else {
            res += letterPos[s[1]];
        }

        output(res);
    }
}

/*
 * File Created: Thursday, 11th February 2021 1:42:08 pm
 * Author: Lukas Rimkus
 */
'use-strict'

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 s = data.shift();

        console.log(b(s));
    }
});

function get_ints() {
    return data[currentLine++].split(' ').map(Number);
}

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

function a(n,arr){
    let k = 0;
    let j = 0;
    for(let i = 0 ; i < n; i++){
        if(arr[i] < 0){
            arr[j++] *= -1;
            arr[i] *= -1;
        }
    }
    if(isSorted(arr)) {
        return 'YES';
    } else {
        return 'NO'
    }
}

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

function b(s) {
    let arr = [];
    for(let i = 97; i <= 122; i++ ){
        for(let j = 97; j <= 122; j++){
            if(i != j) arr.push(String.fromCharCode(i,j));
        }
    }
    let count = 1;
    let index = 0;
    while(true){
        if(s != arr[index]) {
            count++;
            index++;
        } else{
            return count;
        }
    }
}

module.exports = b;

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // input in nodeJs
	var t = nextInt();
	while(hasNext()){
		const stringArr = nextCharArray();
		let a = stringArr[0];
		let b = stringArr[1];

		let first = a.charCodeAt(0) - 97;
		let second = b.charCodeAt(0) - 97;
		// console.log({first, second})
		if (second < first) {
			second++
		}
		// console.log({first, second})

		myout((first * 25) + second );
	}
}

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

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

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

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (s)=>{
    let aCode = 'a'.charCodeAt(0);
    let fIdx = s.charCodeAt(0) - aCode;
    let sIdx = s.charCodeAt(1) - aCode;
    let result = fIdx * 25 + (sIdx < fIdx ? sIdx + 1 : sIdx);
    return result;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let s = readline();
        console.log(`${calc(s)}`);
    }
}

var limit = parseInt(readline());
var alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i",
                           "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
                           "t", "u", "v", "w", "x", "y", "z"];
for (var i = 0; i < limit; i++)
{
    var caseWord = readline();
    var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);
    var secondWordIndex = 0;
    if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))
    {
        secondWordIndex = alphabets.indexOf[1] + 1;
    }
    else
    {
        secondWordIndex = alphabets.indexOf[1];
    }
    var result = firstWordIndex + secondWordIndex;
    print(result);
}

var limit = parseInt(readline());
var alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                           'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
                           't', 'u', 'v', 'w', 'x', 'y', 'z'];
for (var i = 0; i < limit; i++)
{
    var caseWord = readline();
    var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);
    var secondWordIndex = 0
    if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))
    {
        secondWordIndex = alphabets.indexOf[1] + 1;
    }
    else
    {
        secondWordIndex = alphabets.indexOf[1];
    }
    var result = firstWordIndex + secondWordIndex;
    print(result);
}

var limit = parseInt(readline());
var alphabets = ["a", "b", "c", "d", "e", "f", "g", "h", "i",
                           "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
                           "t", "u", "v", "w", "x", "y", "z"];
for (var i = 0; i < limit; i++)
{
    var caseWord = readline();
    var firstWordIndex = 25 * alphabets.indexOf(caseWord[0]);
    var secondWordIndex = 0
    if (alphabets.indexOf(caseWord[0]) > alphabets.indexOf(caseWord[1]))
    {
        secondWordIndex = alphabets.indexOf[1] + 1;
    }
    else
    {
        secondWordIndex = alphabets.indexOf[1];
    }
    var result = firstWordIndex + secondWordIndex;
    print(result);
}

var dict = {};

var alphabet = "abcdefghigklmnopqrstuvwxyz";

var cnt = 1;
for (var i = 0; i < alphabet.length; i++) {
  for (var k = 0; k < alphabet.length; k++) {
    if (i === k) {
      continue;
    }
    dict[alphabet[i] + alphabet[k]] = cnt;
    cnt++;
  }
}

var n = parseInt(readline());

for (var i = 0; i < n; i++) {
  var s = readline();
  print(dict[s]);
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    let arr=new Array(26*26+10);
    let a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    let cnt=0;
    for(let i=0;i<26;i++)
    {
        for(let j=0;j<26;j++)
        {
            if(i!=j) arr[++cnt]=a[i]+a[j];
        }
    }
    for(let i=1;i<=t;i++)
    {
        let str=line[i];
        for(let j=1;j<=cnt;j++)
        {
            if(arr[j]===str)
            {
                console.log(j);
                break;
            }
        }
    }
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var list = [];
	var alpha = "abcdefghijklmnopqrstivwxyz";
	for(var i = 0; i < alpha.length; i++){
		for(var j = 0; j < alpha.length; j++){
			if(i != j){
				list.push(alpha[i] + alpha[j]);
			}
		}
	}
	while(hasNext()){
		var s = next();
		myout(list.indexOf(s) + 1);
	}
}